首页 > 解决方案 > 在 Unity 3D 版本 2019 中绕太阳旋转地球

问题描述

我在统一 3D 中创建了一个场景。它有3个球体,一个是太阳,第二个是地球,第三个是月亮。我让月亮成为地球的孩子。我的地球围绕太阳垂直旋转,月亮围绕地球旋转。我想要水平轴上的旋转。

革命的代码如下:

using UnityEngine;
using System.Collections;

public class revolve : MonoBehaviour {

public Transform target;    // the object to rotate around

public int speed;   // the speed of rotation

void Start()
 {
if (target == null) 
{
target = this.gameObject.transform;
Debug.Log ("RotateAround target not specified. Defaulting to parent GameObject");
}}

// Update is called once per frame
void Update () 
{
// RotateAround takes three arguments, first is the Vector to rotate around
// second is a vector that axis to rotate around
// third is the degrees to rotate, in this case the speed per second
transform.RotateAround(target.transform.position,target.transform.forward,speed * Time.deltaTime);
}}

建议在水平轴上进行哪些更改。

标签: unity3d

解决方案


更改最后一行

 transform.RotateAround(target.transform.position,target.transform.forward,speed * Time.deltaTime);

 transform.RotateAround(target.transform.position,target.transform.right,speed * Time.deltaTime);

推荐阅读