旋轉

一種以歐拉角度量的旋轉。
transform.eulerAngles(x,y,z);
表示繞x,y,z分別旋轉的度數。

注意,只能對其設置絕對角度值,不建議使用+=來設置角度,由於超過360度會出現錯誤,若須要使用+=建議使用Transform.rotate(x,y,z) 。且建議每次賦值都賦全(x,y,z)三個參數。即不建議使用諸如eulerAngles.x=10這樣的賦值。

demo:
    public Transform target;    
    public float yRotation = 5f;    
    public float xRotation = 5f;

    // Use this for initialization
    void Start () { }

    // Update is called once per frame
    void Update () 
    {        
    if (target!=null)       
    {            
      yRotation += Input.GetAxis("Horizontal");           //← →箭頭
      xRotation += Input.GetAxis("Vertical");            //↑ ↓箭頭
      target.eulerAngles = new Vector3(xRotation,yRotation,0);       //按下左右將圍繞Y軸勻速旋轉,按下上下將圍繞X軸勻速旋轉
//這裏如果使用target.rotate(xRotation,yRotation,0),將會發現一開始target圍繞X,Y作5,5旋轉,且是持續的,隨着按上下左右鍵,旋轉的幅度會相應增長或者減小。
     }
     }


比較:transform.eulerAngles(x,y,z);是一種在最原始的基礎上設置其旋轉角x,y,z的。
而transform.rotate(x,y,z);是一種旋轉,設置後,物體將會旋轉指定的x,y,z值。this

相關文章
相關標籤/搜索