04-26-2015, 03:23 PM
Hi!!!
I have several splines in my scene and prefabs of my GameObjects with FollowSpline script attach on them. All i want is to instantiate my object(randomly) once per second on start position one of this splines(randomly), run on it and delete when it comes to the end of this spline.
I have GameManager script with two arrays of spline and objects:
public class CarsManager : MonoBehaviour
{
public MyFollowSpline myFollowSpline;
public float spawnTime = 3f;
public GameObject carItems;
public CurvySpline splinesToFollow;
void Start ()
{
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Spawn ()
{
int spawnSplineIndex = Random.Range (0, splinesToFollow.Length);
int spawnCarIndex = Random.Range (0, carItems.Length);
CurvySpline mySpline = splinesToFollow [spawnSplineIndex];
.......?
}
}
The question is how to instantiate GameObject and attach to it one of this spline in my Spawn method? And how to delete GameObject when it comes to the end of the spline(i think this method has to be in FollowSpline script)?
I have several splines in my scene and prefabs of my GameObjects with FollowSpline script attach on them. All i want is to instantiate my object(randomly) once per second on start position one of this splines(randomly), run on it and delete when it comes to the end of this spline.
I have GameManager script with two arrays of spline and objects:
public class CarsManager : MonoBehaviour
{
public MyFollowSpline myFollowSpline;
public float spawnTime = 3f;
public GameObject carItems;
public CurvySpline splinesToFollow;
void Start ()
{
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Spawn ()
{
int spawnSplineIndex = Random.Range (0, splinesToFollow.Length);
int spawnCarIndex = Random.Range (0, carItems.Length);
CurvySpline mySpline = splinesToFollow [spawnSplineIndex];
.......?
}
}
The question is how to instantiate GameObject and attach to it one of this spline in my Spawn method? And how to delete GameObject when it comes to the end of the spline(i think this method has to be in FollowSpline script)?