欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn)

 更新時(shí)間:2020年01月19日 11:15:35   作者:xiaochenXIHUA  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)物體沿自身的任意軸向旋轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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)

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論