小編給大家分享一下如何使用Unity實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn),希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
宛城網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),宛城網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為宛城成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的宛城做網(wǎng)站的公司定做!
具體內(nèi)容如下
一、創(chuàng)建一個(gè)需要旋轉(zhuǎn)的物體
二、編寫控制該物體的腳本
using UnityEngine; using System.Collections; public class Test_ElectricFan : MonoBehaviour { public bool isOpen=false; //是否開(kāi)始旋轉(zhuǎn) public int speed=2; //旋轉(zhuǎn)的速度 // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(isOpen) { RotateAxisOfSelf(SelfAxis.Y,speed); } } /// <summary> /// 讓物體繞自身的軸旋轉(zhuǎn) /// </summary> /// <param name="AxisX">自身的軸</param> private void RotateAxisOfSelf(SelfAxis selfAxis,int speed=2) { switch(selfAxis) { case SelfAxis.X: this.transform.Rotate (new Vector3(1*Time.deltaTime*speed,0,0)); break; case SelfAxis.Y: this.transform.Rotate (new Vector3(0,1*Time.deltaTime*speed,0)); break; case SelfAxis.Z: this.transform.Rotate (new Vector3(0,0,1*Time.deltaTime*speed)); break; default: this.transform.Rotate (new Vector3(1*Time.deltaTime*speed,0,0)); break; } } //枚舉軸 enum SelfAxis { X, Y, Z, } }
三、將編寫好的控制物體的腳本添加給需要沿自身任意軸旋轉(zhuǎn)的物體上,然后運(yùn)行程序,接著點(diǎn)擊IsOpen打鉤此時(shí)物體開(kāi)始旋轉(zhuǎn)
看完了這篇文章,相信你對(duì)“如何使用Unity實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn)”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
網(wǎng)站名稱:如何使用Unity實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn)
轉(zhuǎn)載注明:http://jinyejixie.com/article26/iejsjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、虛擬主機(jī)、服務(wù)器托管、標(biāo)簽優(yōu)化、網(wǎng)站內(nèi)鏈、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)