unity製做月球地球太陽的公轉和自轉

自轉:this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateObj : MonoBehaviour
{
    // Start is called before the first frame update
    public float rotateSpeed = 10f;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.Rotate(Vector3.up * rotateSpeed);
    }
}

公轉:code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rotateArroundOther : MonoBehaviour
{
    public Transform target;
    public float rotateSpeed = 10f;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.RotateAround(target.position, Vector3.up , rotateSpeed);
    }
}
相關文章
相關標籤/搜索