Unity實(shí)現(xiàn)手機(jī)搖一搖震動
更新時間:2019年11月04日 08:32:36 作者:liang_704959721
這篇文章主要為大家詳細(xì)介紹了untiy實(shí)現(xiàn)手機(jī)搖一搖震動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
在手機(jī)經(jīng)常使用搖一搖這種操作方式,在unity中也可以實(shí)現(xiàn)震動,iPhone與Android的函數(shù)不一樣,在ios中用的函數(shù)為iPhoneUtils.Vibrate()在Android中函數(shù)為Handheld.Vibrate();
具體代碼:
using UnityEngine;
using System.Collections;
public class FunctionVibrate : MonoBehaviour
{
//實(shí)現(xiàn)手機(jī)晃動震動效果
// 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!"))
//{
// //震動
// 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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
C# CAD SelectionFilter下TypedValue數(shù)組使用方式
這篇文章主要介紹了C# CAD SelectionFilter下TypedValue數(shù)組使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
C# datatable 不能通過已刪除的行訪問該行的信息處理方法
采用datatable.Rows[i].Delete()刪除行后再訪問該表時出現(xiàn)出現(xiàn)“不能通過已刪除的行訪問該行的信息”的錯誤2012-11-11

