I am instantiating an object, and I need the instantiated object’s transform. Problem is, the instantiated object is an Object, not a GameObject - so I cant seem to access its transform. So I tried to type cast it using player = (GameObject)Instantiate… but it says its an invalid cast.
How can I get the transform of my instantiated object??’
Thanks very much.
This is my spawn script:
private GameObject player; // reference to instantiated player
private Transform playersTransform;
private Camera camera; //referemce to camera.
private CameraControllercs target;
void SpawnBlueTeamPlayer() //find BLUE spawn points and put them into an array.
{
blueSpawnPoints = GameObject.FindGameObjectsWithTag("SpawnBlueTeam");
//randomly select one of the spawn points
GameObject randomBlueSpawn = blueSpawnPoints[Random.Range(0, blueSpawnPoints.Length)];
//Instantiate player at the randomly selected point.
player = (GameObject)Network.Instantiate(blueTeamPlayer, randomBlueSpawn.transform.position, randomBlueSpawn.transform.rotation, blueTeamGroup);
playersTransform = player.transform;
camera = Camera.main;
target = camera.GetComponent<CameraControllercs>();
target.target = player.transform;
}
Target goes to my camera script which sets the target of my camera.