本文實(shí)例為大家分享了Unity控制指針旋轉(zhuǎn)到指定位置的具體代碼,供大家參考,具體內(nèi)容如下
一、搭建基礎(chǔ)的表盤、指針
二、編寫控制指針旋轉(zhuǎn)到指定位置的腳本:
using UnityEngine; using System.Collections; public class Test_OnDashboard : MonoBehaviour { public int thiAngle = 0; public int rotateSpeed = 2; public bool openRotate = false; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.T)) { openRotate = true; StartCoroutine(stop()); } if (openRotate) { PointerRotate(); } } ////// 控制指針旋轉(zhuǎn) /// private void PointerRotate() { if (thiAngle > -0.001f && thiAngle <= 180) { Quaternion target = Quaternion.Euler(0, 0, (90 - thiAngle)); transform.rotation = Quaternion.RotateTowards(transform.rotation, target, rotateSpeed); } } ////// 停止檢測 /// ///private IEnumerator stop() { yield return new WaitForSeconds(2); openRotate =false; Debug.Log("tingzhi"); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。