Unity3d 在Unity 3D版本2019中围绕太阳旋转地球
我已经在unity 3D中创建了一个场景。它有三个球体,一个是太阳,第二个是地球,第三个是月亮。我已使月亮成为地球的孩子。我的地球垂直地绕着太阳转,月亮绕着地球转。我想要在水平轴上旋转 革命的代码如下:Unity3d 在Unity 3D版本2019中围绕太阳旋转地球,unity3d,Unity3d,我已经在unity 3D中创建了一个场景。它有三个球体,一个是太阳,第二个是地球,第三个是月亮。我已使月亮成为地球的孩子。我的地球垂直地绕着太阳转,月亮绕着地球转。我想要在水平轴上旋转 革命的代码如下: using UnityEngine; using System.Collections; public class revolve : MonoBehaviour { public Transform target; // the object to rotate around pu
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);
}}
建议在水平轴上旋转所做的更改。更改最后一行
transform.RotateAround(target.transform.position,target.transform.forward,speed * Time.deltaTime);
到
transform.RotateAround(target.transform.position,target.transform.right,speed * Time.deltaTime);