Fork me on GitHub

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),填写旋转速度。

 

posted @ 2015-03-12 21:57  何海洋  阅读(7941)  评论(0编辑  收藏  举报