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的主要的工具分布和对应工具的相关的功 ...
随机推荐
- 【转载】关于C#静态构造函数的几点说明
一.定义 静态构造函数是C#的一个新特性,其实好像很少用到.不过当我们想初始化一些静态变量的时候就需要用到它了.这个构造函数是属于类的,而不是属于哪里实例的,就是说这个构造函数只会被执行一次.也就是在 ...
- 系统去掉 Android 4.4.2 的StatusBar和NavigationBar
1. System Bar简单介绍 在Android4.0 (API Level 14)及更高版本号中.System Bar由Status Bar<位于顶部>和Navigation Bar ...
- 菜鸟系列之C/C++经典试题(三)
设计包括min函数的栈 题目:定义栈的数据结构,要求加入一个min函数,可以得到栈的最小元素.要求函数min.push以及pop的时间复杂度都是O(1). 分析:这是2006年google的一道面试题 ...
- 代码调试过程中easy遇到的问题
前两天身体有些不舒服,也没写啥新文章,昨天下了一天的雨.今天阳光明媚,空气也非常新奇.心情大好. 继翻译为什么输出是String而不是Object,今天先写一下调试方面的东西.java中自带的函数调试 ...
- angularjs学习之八(angularjs中isolate scope的使用)
angular js中指令directive有个特别实用的东西,那就是 isolate scope (被隔离的scope) 关于详细他和全局的scope 有什么差别.能够參考以下这篇博文: Angul ...
- c++vector简单实现
const int DEFAULT_CAP = 3; template <typename T> class vector { // int capacity; T* _data; int ...
- 直播:中国HBase技术社区第一届MeetUp
6月6日,由中国HBase技术社区组织,阿里云主办的中国第一届HBase Meetup将在北京举行,来自阿里.小米.滴滴.360等公司的各位大神会共同探讨HBase2.0的技术革新,HBase在国内各 ...
- ermissions on /usr/local/mongodb/conf/keyFile are too open
ermissions on /usr/local/mongodb/conf/keyFile are too open > rs.initiate(cfg); { "ok" : ...
- gcc 头文件是用户应用程序和函数库之间的桥梁和纽带 功能的真正逻辑实现是以硬件层为基础
gcc GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) http://gcc.gnu.o ...
- ios 短音效的使用
1.通用短音效ID的获取 #import <Foundation/Foundation.h> @interface MJAudioTool : NSObject /** * 播放音效 * ...