Unity手机摇一摇
生活随笔
收集整理的这篇文章主要介绍了
Unity手机摇一摇
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
2019独角兽企业重金招聘Python工程师标准>>>
项目中遇到手机摇一摇功能边整理下:
using UnityEngine; using System.Collections;public class ShakePhone : MonoBehaviour {float old_y = 0;float new_y = 0;float max_y = 0;float min_y = 0;float d_y = 0;void Update(){new_y = Input.acceleration.y;d_y = new_y - old_y;old_y = new_y;if (Input.GetKey(KeyCode.Escape)){Application.Quit();}}int i;void OnGUI(){GUI.Label(new Rect(100, 100, 100, 100), "g:" + Input.acceleration + "d_y:" + d_y);GUI.Label(new Rect(100, 210, 100, 100), "i:" + i);if (d_y > 2){i++;Handheld.Vibrate(); //手机的震动效果}} }转载于:https://my.oschina.net/u/698044/blog/510165
总结
以上是生活随笔为你收集整理的Unity手机摇一摇的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 卸载Android app弹出浏览器的一
- 下一篇: Robots.txt 协议详解及使用说明