Unity3D第一課之自轉與公轉


1、物體公轉,即圍繞一個中心物體旋轉

public class gongzhuan : MonoBehaviour {

    public GameObject Axis;//軸,用於選擇圍繞中心

    public float RotateSpeed;//旋轉速度// Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        this.transform.RotateAround (Axis.transform.position, Vector3.up,RotateSpeed);        
    }
}

  將腳本拖動到物體上(此處為gongzhuan),同時選擇圍繞中心物體(此處為s),填寫旋轉速度。


 

2、物體自轉,即以自己為中心旋轉

public class zizhuan : MonoBehaviour {

    public float RotateSpeed;//旋轉速度

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        transform.Rotate(Vector3.down* RotateSpeed,Space.World);
    }
}

  將腳本拖動到物體上(此處為zizhuan),填寫旋轉速度。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM