Rotate RotateAround

1.新建2个Sphere的GameObject,分别命名为Earth,Sun,顺便给个direct light也行。材质,贴图个人喜好了。

2.新建个脚本,并绑定至其中一个GameObject。内容如下:

using UnityEngine;

namespace Assets.script
{
    public class EarthCtrl : MonoBehaviour
    {
        private GameObject _earth;
        private GameObject _sun;
        private GameObject _mycamera;
        // Use this for initialization
        private void Start()
        {
            _sun = GameObject.Find("Sun");
            _earth = GameObject.Find("Earth");
            _mycamera = GameObject.Find("Main Camera");
        }

        // Update is called once per frame
        private void Update()
        {

            _earth.transform.Rotate(Vector3.up);    //  地球自转
            _earth.transform.RotateAround(_sun.transform.position, Vector3.up, 1f);     //地球围绕太阳转
            _mycamera.transform.RotateAround(_sun.transform.position, Vector3.up, 0.1f);    //相机,也就是我们围绕太阳转,但是总给人是太阳围绕我们转到错觉,好吧,地心说了
        }
    }
}
View Code

 

posted @ 2013-09-03 13:33  eyotata  阅读(615)  评论(0编辑  收藏  举报