Unity控制指針旋轉(zhuǎn)到指定位置
本文實例為大家分享了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();
 
 }
 
 }
 
 /// <summary>
 /// 控制指針旋轉(zhuǎn)
 /// </summary>
 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);
 }
 
 
 
 }
 
 /// <summary>
 /// 停止檢測
 /// </summary>
 /// <returns></returns>
 private IEnumerator stop()
 {
 yield return new WaitForSeconds(2);
 openRotate =false;
 Debug.Log("tingzhi");
 }
 
}
三、將該腳本添加給指針物體,然后運行輸入對應(yīng)的旋轉(zhuǎn)角度指針即可旋轉(zhuǎn)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
欄 目:C#教程
下一篇:Unity3D實現(xiàn)控制攝像機(jī)移動
本文標(biāo)題:Unity控制指針旋轉(zhuǎn)到指定位置
本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/4912.html
您可能感興趣的文章


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
 - 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
 - 01-10WinForm限制窗體不能移到屏幕外的方法
 - 01-10WinForm繪制圓角的方法
 - 01-10C#實現(xiàn)txt定位指定行完整實例
 - 01-10WinForm實現(xiàn)仿視頻播放器左下角滾動新
 - 01-10C#停止線程的方法
 - 01-10C#實現(xiàn)清空回收站的方法
 - 01-10C#通過重寫Panel改變邊框顏色與寬度的
 - 01-10C#實現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
 
隨機(jī)閱讀
- 01-10C#中split用法實例總結(jié)
 - 04-02jquery與jsp,用jquery
 - 01-10使用C語言求解撲克牌的順子及n個骰子
 - 08-05DEDE織夢data目錄下的sessions文件夾有什
 - 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-10delphi制作wav文件的方法
 - 01-11ajax實現(xiàn)頁面的局部加載
 - 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
 - 08-05織夢dedecms什么時候用欄目交叉功能?
 


