Unity陀螺仪
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陀螺仪的更多相关文章
- Unity 根据手机陀螺仪,实现流动UI效果
Unity 根据手机陀螺仪,实现流动UI效果 设置Canvas 模式设置为 Screen Space - Camera 指定Camera 挂载脚本 挂载Target using System; usi ...
- Unity 使用 陀螺仪 实现 《王者荣耀》 登入界面 背景动态效果
在 <王者荣耀> 登入界面 左右上下晃动手机(有些手机不支持)可以看到背景在变化 我使用的是iPhone SE 效果如下: 对比两张图片的左下角 可以看到差异 至于为什么要这么做: 1.使 ...
- 【Unity编程】欧拉角与万向节死锁(图文版)
版权声明:本文为博主原创文章,欢迎转载.请保留博主链接:http://blog.csdn.net/andrewfan 万向节死锁(Gimbal Lock)问题 上文中曾经说过,欧拉旋转的顺规和轴向定义 ...
- UNITY VR 视频/图片 开发心得(一)
现在的VR似乎没有之前那么火热了,于是乎我居然开始了VR征程... 说起VR,对于没有接受过相关知识的人来说可能看起来比较高大上,但是VR的原理却没有想象中那么复杂.总的来说,VR之所以能够产生立体感 ...
- Unity Remote 无法连接
前言 Unity Remote支持把手机的以下数据返回到Unity Editor中: 触摸输入 加速计 陀螺仪 摄像头 GPS 我的操作环境: Unity 5.3.6f1 在windows 下 And ...
- 《图说VR入门》——DeepoonVR的大鹏(陀螺仪)枪
<图说VR入门>--VR大朋的(陀螺仪)枪 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/ar ...
- Unity做360度的全景照片
这里推荐两种方法,第一种是用鼠标滑动,第二种是用手机的陀螺仪进行全景查看 第一种: 1.新建一Sphere,然后为其赋予材质,注意材质的Shader类型为:Mobile/particles/Alpha ...
- Unity中的输入
目录 移动平台的输入 触摸 触摸相关的函数 触摸的一个示例 重力加速器 在Unity中访问重力加速器的信息 重力加速器示例 虚拟键盘 其他输入 传统的输入 鼠标,键盘,控制杆,手柄 虚拟控制轴(Vir ...
- Unity3d入门 - 关于unity工具的熟悉
上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...
随机推荐
- odoo写邮件添加收件人
在任何可以写消息的地方点击鼠标 或者回复消息 写消息的框会聚焦并变大 点击撰写框右上角的弹出窗图标 弹出完整的撰写消息窗口 在红色的地方添加收件 ...
- c 链表之 快慢指针 查找循环节点(转)
上面分析了 根据这张图 推倒出 数学公式. 刚接触 不能一下弄明白.下面结合上面文章的分析.仔细推倒一下 , 一般设置 快指针 速度是 慢指针的2倍.及 快指针每次遍历两个指针, 慢指针每次遍历1个指 ...
- swift,demo,ios8
swift交流群:342581988,欢迎增加. 刚刚写的小 demo.搞得还是不是太好.请大家拍砖! 能够直接复制执行 import UIKit class ViewController: UIVi ...
- Using Virtual Serial Ports on Linux (Ubuntu)
http://www.xappsoftware.com/wordpress/2013/10/07/using-virtual-serial-ports-on-linux-ubuntu/?goback= ...
- angularjs中常见错误
使用angularjs时间不是非常长,理解不够透彻.但为刚開始学习的人还是能够帮助点的. 1.回调函数. . ...-->切记它是异步的,出现莫名其妙的问题记得查看一下 2.内存泄露. .... ...
- mysql中修改表字段名/字段长度/字段类型详解
在mysql中我们对数据表字段的修改命令只要使用alter就可以了,下面我来给大家详细介绍mysql中修改表字段名/字段长度/字段类型等等一些方法介绍,有需要了解的朋友可参考. 先来看看常用的方法 M ...
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决的方法
今天在使用android studio在Genymotion上调试程序出现INSTALL_FAILED_CPU_ABI_INCOMPATIBLE导致程序安装不了: 后来百度发现是要安装:http:// ...
- VUE 之 JS指令
1.v-text的用法: 2.v-html 3.v-for 4.v-if , v-else if ,v-else v-if 每次生成都只有一个标签,即符合条件的标签. 5.v-show v-show ...
- physical processor, core, logical processor
Processor Groups https://docs.microsoft.com/en-us/windows/desktop/ProcThread/processor-groups The 64 ...
- box-sizing: border-box;的作用
box-sizing 属性可以被用来调整这些表现: content-box 是默认值.如果你设置一个元素的宽为100px,那么这个元素的内容区会有100px宽,并且任何边框和内边距的宽度都会被增加到 ...