Graphics Reference
In-Depth Information
// store this object in our list of objects
objectList.Add(tempTrans);
// return the object to whatever was calling
return tempTrans;
}
For occasions where it is preferable to return a newly instantiated object's gameObject
rather than the transform, the SpawnGO (GO being short for GameObject) function is
available. It works exactly the same as the Spawn function, but instead of returning the
newly instantiated object's transform, it returns its gameObject.
// here we just provide a convenient function to return the spawned
// objects gameobject rather than its transform
public GameObject SpawnGO(GameObject anObject, Vector3 aPosition,
Quaternion aRotation)
{
if(objectList==null)
objectList=new ArrayList();
// instantiate the object
tempGO=(GameObject)Instantiate(anObject, aPosition,
aRotation);
tempTrans= tempGO.transform;
// store this object in our list of objects
objectList.Add(tempTrans);
// return the object to whatever was calling
return tempGO;
}
The SpawnController.cs script track every object that it has created. Each one is stored
in the array (an ArrayList type variable) named objectList. To have SpawnController.cs
return the whole list, the function GetAllSpawnedTransforms() is provided.
public ArrayList GetAllSpawnedTransforms()
{
return objectList;
}
}
4.3.2 Trigger Spawner
The TriggerSpawner.cs script instantiates an object when another object enters the trigger
to which the script is attached. One such use for this script would be to spawn an enemy
when the player reaches a particular area in a level:
public class TriggerSpawner : MonoBehavior
{
Search WWH ::




Custom Search