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);
    }
}
相关文章
相关标签/搜索