脚本代码如下
using UnityEngine;
using System.Collections;
//围绕某个物体 转动
public class RotateAroundBehavior : MonoBehaviour
{
private int numOrbiters;
//要围绕哪一个物体旋转
public GameObject sourceObject;
//围绕旋的物体
public GameObject[] orbiters;
//旋转的圆的轨道的大小X
public int orbitRadiusX = 3;
//旋转的圆的轨道的大小Y
public int orbitRadiusY = 3;
//旋转的圆的轨道的大小Z
public int orbitRadiusZ = 3;
//围绕哪一个轴转
public string shaft = "y";
//旋转的速度
public float RoutateSpped = 10;
// Use this for initialization
void Start()
{
numOrbiters = orbiters.Length;
Init();
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < numOrbiters; i++)
{
if (i < orbiters.Length)
{
UpdateOrbiterPosition(i);
}
}
}
void Init()
{
//set initial positions of balls
//1 ball can be anywhere
//2 balls should be opposite
SetOrbiterPositions();
}
void AddOrbiter()
{
numOrbiters++;
SetO