因此,无论何时按下按钮,我都会制作一个测试游戏,它会从工厂类创建一个类对象。我希望每当我生成一个对象时都这样做,它不会重叠其他对象。此外,我想在每次产卵时将球体和光对象保持在一起。你能帮我弄明白怎么做吗?
public class Sphere : Shape
{
public Sphere()
{
float speed = 10f;
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = new Vector3(0, 0, 0);
sphere.GetComponent<MeshRenderer>().material.color = Random.ColorHSV();
sphere.transform.Rotate(Vector3.up, speed * Time.deltaTime);
Destroy(sphere, 30.0f);
GameObject lightGameObject = new GameObject("Light");
Light lightComp = lightGameObject.AddComponent<Light>();
lightComp.color = Random.ColorHSV();
lightGameObject.transform.position = new Vector3(0, 0, 0);
lightGameObject.transform.Rotate(Vector3.up, speed * Time.deltaTime);
Destroy(lightComp, 30.0f);
}
}