using UnityEngine;
using System.Collections;
using UnityEngine.UI;
//摄像机 陀螺仪转动
public class TGyro : MonoBehaviour
{ //bool gyroBool;
Gyroscope gyro;
Quaternion quatMult;
Quaternion quatMap;
//UILabel ul;
public GameObject player;
public GameObject camParent;
void Awake()
{
//player = GameObject.Find("Player");
// find the current parent of the camera's transform
Transform currentParent = transform.parent;
// instantiate a new transform
camParent = new GameObject("camParent");
// match the transform to the camera position
camParent.transform.position = transform.position;
// make the new transform the parent of the camera transform
transform.parent = camParent.transform;
// make the original parent the grandparent of the camera transform
//camParent.transform.parent = currentParent;-
// instantiate a new transform
GameObject camGrandparent = new GameObject("camGrandParent");
// match the transform to the camera position
camGrandparent.transform.position = transform.position;
// make the new transform the parent of the camera transform
camParent.transform.parent = camGrandparent.transform;
// make the original parent the grandparent of the camera transform
camGrandparent.transform.parent = currentParent; //gyroBool = true;
//if (gyroBool) {
gyro = Input.gyro;
//ul = GameObject.Find("Rotation").GetComponent<UILabel>(); gyro.enabled = true;
camParent.transform.eulerAngles = new Vector3(0,0, 0);
quatMult = new Quaternion(0, 0, 1, 0);//猜测陀螺仪默认是向下的,这里是沿z轴转180度 } void Update()
{ quatMap = new Quaternion(gyro.attitude.x, gyro.attitude.y, gyro.attitude.z, gyro.attitude.w);
Quaternion qt=quatMap * quatMult; transform.localRotation =qt; //ul.text = "Rotation:" + transform.localRotation + "player" + player.transform.localRotation; } }

Unity陀螺仪的更多相关文章

  1. Unity 根据手机陀螺仪,实现流动UI效果

    Unity 根据手机陀螺仪,实现流动UI效果 设置Canvas 模式设置为 Screen Space - Camera 指定Camera 挂载脚本 挂载Target using System; usi ...

  2. Unity 使用 陀螺仪 实现 《王者荣耀》 登入界面 背景动态效果

    在 <王者荣耀> 登入界面 左右上下晃动手机(有些手机不支持)可以看到背景在变化 我使用的是iPhone SE 效果如下: 对比两张图片的左下角 可以看到差异 至于为什么要这么做: 1.使 ...

  3. 【Unity编程】欧拉角与万向节死锁(图文版)

    版权声明:本文为博主原创文章,欢迎转载.请保留博主链接:http://blog.csdn.net/andrewfan 万向节死锁(Gimbal Lock)问题 上文中曾经说过,欧拉旋转的顺规和轴向定义 ...

  4. UNITY VR 视频/图片 开发心得(一)

    现在的VR似乎没有之前那么火热了,于是乎我居然开始了VR征程... 说起VR,对于没有接受过相关知识的人来说可能看起来比较高大上,但是VR的原理却没有想象中那么复杂.总的来说,VR之所以能够产生立体感 ...

  5. Unity Remote 无法连接

    前言 Unity Remote支持把手机的以下数据返回到Unity Editor中: 触摸输入 加速计 陀螺仪 摄像头 GPS 我的操作环境: Unity 5.3.6f1 在windows 下 And ...

  6. 《图说VR入门》——DeepoonVR的大鹏(陀螺仪)枪

    <图说VR入门>--VR大朋的(陀螺仪)枪 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/ar ...

  7. Unity做360度的全景照片

    这里推荐两种方法,第一种是用鼠标滑动,第二种是用手机的陀螺仪进行全景查看 第一种: 1.新建一Sphere,然后为其赋予材质,注意材质的Shader类型为:Mobile/particles/Alpha ...

  8. Unity中的输入

    目录 移动平台的输入 触摸 触摸相关的函数 触摸的一个示例 重力加速器 在Unity中访问重力加速器的信息 重力加速器示例 虚拟键盘 其他输入 传统的输入 鼠标,键盘,控制杆,手柄 虚拟控制轴(Vir ...

  9. Unity3d入门 - 关于unity工具的熟悉

    上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...

随机推荐

  1. SolidEdge如何绘制变化半径倒圆角

    1 在要变化半径的边上打一些点   2 点击倒角命令的参数对话框,选择可变半径   3 选择倒角的直线,右击确认,再依次点击关键点,修改倒角数值,修改之后按回车,继续下一个点,直到结束.  

  2. 通过Java反射做实体查询

    我们在使用hibernate的时候,查询的时候都会和实体中的一些字段相结合去查询,当然字段少了,还算是比较简单,当字段多了,就不那么容易了,所以就自己写了个方法,根据实体中的字段信息去查询,废话不多说 ...

  3. FastDFS的配置、部署与API使用解读(4)FastDFS配置详解之Client配置(转)

    一种方式是通过调用ClientGlobal类的初始化方法对配置文件进行加载,另一种是通过调用API逐一设置配置参数.后一种方式对于使用Zookeeper等加载属性的方式很方便. 1. 加载配置文件: ...

  4. Asp.net常用的51个代码(非常实用)

    1.//弹出对话框.点击转向指定页面 Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script> ...

  5. 《从零開始学Swift》学习笔记(Day 61)——Core Foundation框架之内存管理

    原创文章,欢迎转载. 转载请注明:关东升的博客 在Swift原生数据类型.Foundation框架数据类型和Core Foundation框架数据类型之间转换过程中,尽管是大部分是能够零开销桥接,零开 ...

  6. C# List Find方法

    https://blog.csdn.net/knqiufan/article/details/77847143

  7. C++设计模式之State模式

    这里有两个例子: 1.https://www.cnblogs.com/wanggary/archive/2011/04/21/2024117.html 2.https://www.cnblogs.co ...

  8. Mysql常见函数

    一.单行函数 1.字符函数 concat拼接 substr截取子串 upper转换成大写 lower转换成小写 trim去前后指定的空格和字符 ltrim去左边空格 rtrim去右边空格 replac ...

  9. Objective-C - - 字符串与数字互相转换

    NSString *string = @"123"; // 1.字符串转int int intString = [string intValue]; // 2.int装字符串 NS ...

  10. Silverlight 2中实现文件上传和电子邮件发送

    Silverlight 2中实现文件上传和电子邮件发送 [收藏此页] [打印]   作者:IT168 TerryLee  2008-05-30 内容导航: 使用Web Service上传文件   [I ...