How can i set a location for this to spawn?
#pragma strict
var objectToSpawn : Transform;
var canRespawn = true;
function Update ()
{
if(canRespawn)
{
SpawnObjects();
}
}
function SpawnObjects ()
{
canRespawn = false;
yield WaitForSeconds(1);
Instantiate(objectToSpawn,gameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
canRespawn = true;
}
So if you want an object that is attached to the object - you were nearly right, but you use transform.FindChild() instead of GameObject.Find(). This code finds a direct child called SpawnPoint:
Instantiate(objectToSpawn, transform.FindChild("SpawnPoint").position, Quaternion.identity);
Or you could actually create a spawn point variable and set it in the inspector:
var spawnPoint : Transform;
...
Instantiate(objectToSpawn, spawnPoint.position, Quaternion.identity);
You could declare a Vector3 spawnLocation in that class, or a Transform (it gives you a gizmos, easier to manipulate. You could have a gizmos with an editor script, but that’s a bit more work), or an array of Vector3 and a Random index, or an array of Transform. Or a radius and Random.insideUnitCircle. Or two Random.value for a rectangle.
All I got right now, but there is plenty of ways.