zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    常用模块
    二分查找算法
    递归函数
    文件操作
    day02--Python基础二(基础数据类型)
    Python学习笔记day01--Python基础
    Python2X和Python3X的区别
    testdisk修复文件系统
    机器学习入门 快速版
    tableau教程 快速入门
  • 原文地址:https://www.cnblogs.com/lansor/p/3298561.html
Copyright © 2011-2022 走看看