欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)手機(jī)搖一搖震動(dòng)

 更新時(shí)間:2019年11月04日 08:32:36   作者:liang_704959721  
這篇文章主要為大家詳細(xì)介紹了untiy實(shí)現(xiàn)手機(jī)搖一搖震動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在手機(jī)經(jīng)常使用搖一搖這種操作方式,在unity中也可以實(shí)現(xiàn)震動(dòng),iPhone與Android的函數(shù)不一樣,在ios中用的函數(shù)為iPhoneUtils.Vibrate()在Android中函數(shù)為Handheld.Vibrate();

具體代碼:

using UnityEngine;
using System.Collections;
 
public class FunctionVibrate : MonoBehaviour
{
 //實(shí)現(xiàn)手機(jī)晃動(dòng)震動(dòng)效果
 // Use this for initialization
 float old_y = 0;
 float new_y;
 float max_y = 0;
 float min_y = 0;
 float d_y = 0;
 public float distance = 0.3f;
 void Start () {
 
 }
 
 // Update is called once per frame
 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() 
 {
 //if(GUI.Button(new Rect(0,100,100,32),"vibrate!"))
 //{
 // //震動(dòng)
 // Handheld.Vibrate();
 //}
 GUI.Label(new Rect(100,100,100,100),"g:"+Input.acceleration+"d_y:"+d_y);
 GUI.Label(new Rect(100,200,100,100),"i:"+i);
 if(d_y>distance)
 {
  i++;
  Handheld.Vibrate();
 }
 }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論