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

Unity3D第一课之自转与公转


 

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

Unity3D第一课之自转与公转

 

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2021-09-28
  • 2021-07-15
  • 2021-06-17
  • 2022-01-30
  • 2022-12-23
猜你喜欢
  • 2021-05-14
  • 2021-11-17
  • 2022-12-23
  • 2021-11-26
  • 2021-08-18
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案