Graphics Reference
In-Depth Information
tempGO=(GameObject)Instantiate(anObject, aPosition,
aRotation);
tempTrans= tempGO.transform;
// return the object to whatever was calling
return tempTrans;
}
// 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)
{
// instantiate the object
tempGO=(GameObject)Instantiate(anObject, aPosition,
aRotation);
tempTrans= tempGO.transform;
// return the object to whatever was calling
return tempGO;
}
public ArrayList GetAllSpawnedPlayers()
{
return playerTransforms;
}
}
4.3.1.1 Script Breakdown
The SpawnController class derives from ScriptableObject:
public class SpawnController : ScriptableObject
{
After the variable declarations, SpawnController.cs sets up as a singleton. As it says in
the comments, this code is based on the work of AngryAnt (published on the Unity wiki
site http://wiki.unity3d.com/index.php?title=Singleton). Recall that the singleton pattern
was discussed earlier in Chapter 2. If you missed it, this just takes care of only ever having
one instance of the script in existence at any time so that we always use the same instance
regardless of where or how it is accessed by other scripts.
private static SpawnController instance;
public SpawnController ()
{
// this function will be called whenever an instance of the
// SpawnController class is made
// first, we check that an instance does not already exist
// (this is a singleton, after all!)
if (instance != null)
Search WWH ::




Custom Search