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