正好要做一个天空的场景,想添加上行星和恒星的自转和公转,代码如下
1.自转。
public float _RotationSpeed; //定义自转的速度
transform.Rotate(Vector3.down*_RotationSpeed,Space.World); //物体自转
2.公转
public GameObject Axis; //物体需要公转的参照物
public float _RotationSpeed; //公转速度
this.transform.RotateAround(Axis.transform.position, Vector3.up, _RotationSpeed);//将需要公转的参照物拖入,设置公转