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. iPhone 适配之路

    (1)1x时代 2007年,初代iPhone公布,屏幕的宽高是320*480像素.这个分辨率一直到iPhone3GS也保持不变. 那时编写iOS的App应用程序.仅仅支持绝对定位. 比方一个butto ...

  2. 数据结构与算法之贪心算法 C++实现

    1.基本思路:从问题的某一个初始解触发逐步逼近给定的目标,以尽可能快的求得更好的解. 当达到算法中某一步不能再继续前进时.就停止算法,给出近似值.也就是说贪心算法并不从总体最优考虑,它所作出的选择仅仅 ...

  3. python xmlrpc

    rpc 协议 RPC = Remote Procedure Call Protocol,即远程过程调用协议. xml rpc 协议 使用http协议作为传输协议,使用xml文本传输命令和数据的一种协议 ...

  4. snip_opencv环境配置和测试程序

    opencv2.4.9环境变量配置的记录. 2014年8月10日 Microsoft Windows XP [版本 5.1.2600](C) 版权所有 1985-2001 Microsoft Corp ...

  5. intellij IDEA 更新java后不用重启tomcat

    最近项目大了,每次修改后重启都要等和很久,那个煎熬…… 为了解决这个问题,万能的Google  装了这个  JREBEL 5.63最新的 安装步骤: 一.IDEA在线搜索 jrebel  安装 二.破 ...

  6. kafka 和 zookeeper 常用命令记录

    启动zookeeper zkServer.sh start 启动kafka服务器 kafka-server-start.sh /software/kafka_2.10-0.10.2.1/config/ ...

  7. mysql优化-----索引覆盖

    一道面试题: 有商品表, 有主键,goods_id, 栏目列 cat_id, 价格price 说:在价格列上已经加了索引,但按价格查询还是很慢,问可能是什么原因,怎么解决? 答:在实际场景中,一个电商 ...

  8. react native 中的redux

    一.使用redux 的条件: 1.某个组件的状态,需要共享: 2.某个状态需要在任何地方都可以拿到: 3.一个组件需要改变全局状态: 4.一个组件需要改变另一个组件的状态. redux   说明白点, ...

  9. 学习html5 中的canvas(一)

    1.canvas画直线 <!doctype html> <html> <head> <meta charset="UTF-8"> & ...

  10. php与html 表单的结合

    PHP $_POST <!DOCTYPE html> <html> <body> <form method="post" action=& ...