這篇文章給大家介紹Unity怎么實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
本文實(shí)例為大家分享了Unity實(shí)現(xiàn)物體沿任意軸向旋轉(zhuǎn),供大家參考,具體內(nèi)容如下
一、創(chuàng)建一個(gè)需要旋轉(zhuǎn)的物體
二、編寫控制該物體的腳本
using UnityEngine;using System.Collections; public class Test_ElectricFan : MonoBehaviour { public bool isOpen=false; //是否開始旋轉(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í)物體開始旋轉(zhuǎn)
關(guān)于Unity怎么實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享題目:Unity怎么實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn)-創(chuàng)新互聯(lián)
文章地址:http://aaarwkj.com/article4/dohpoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、定制網(wǎng)站、面包屑導(dǎo)航、App設(shè)計(jì)、自適應(yīng)網(wǎ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í)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容