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的主要的工具分布和对应工具的相关的功 ...
随机推荐
- nrf51822中app_button 的应用
Button Handler(按键处理程序) 按键处理程序是使用GPIOTE(GPIO Task and Event)的处理机制实现的,为了防止按键的抖动.在GPIOTE event(事件)处理程序中 ...
- 关于Java中强制类型转换的问题
为了更好的理解我们先看下面的例子: package com.yonyou.test; import java.util.ArrayList; import java.util.Iterator; im ...
- nc和telnet配合使用
nc -l 9932 -c 用nc监听9932端口 telnet 180.150.184.115 29933 telnet 29932 端口
- nextSibling和previousSibling
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 在线API
JExcelApi http://jexcelapi.sourceforge.net/resources/javadocs/index.html Poi http://poi.apache.org/a ...
- WPF中如何使用代码操作数据模板生成的控件
有一个Listbox,里面的Item是通过数据模板生成的,如下所示: <Border Margin="15" BorderBrush="Aqua" Bor ...
- 【读书笔记】iOS-GCD-用法
代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { dispatch_async(dispatch_get_gl ...
- 在C语言中使用libb64进行Base64编解码
libb64下载地址http://sourceforge.net/projects/libb64 以下为Demo libb64_demo.c #include <stdio.h> #inc ...
- Kafka在Windows安装运行
摘要:本文主要说明了如何在Windows安装运行Kafka 一.安装JDK 过程比较简单,这里不做说明. 最后打开cmd输入如下内容,表示安装成功 二.安装zooeleeper 下载安装包:http: ...
- bzoj 2301 [HAOI2011]Problem b(莫比乌斯反演+分块优化)
题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 1≤n≤50000,1≤a≤b≤50000, ...