Question by
Bluesharky38 · Jun 22, 2020 at 05:28 PM ·
randomprefabschildspawning
Making an object spawned from a list became a child of the player?
So for my game, I have my player spawn a robot from a random selection of the prefabs I've attached to the player.
I want the spawned robots to be children of the player that spawned them, but I can't figure out how to do it with how things are set up?
Here is the code for how the robots are spawned
void SpawningRobot()
{
if (Input.GetKeyDown(KeyCode.Space) && Time.time > CanSpawn)
{
CanSpawn = Time.time + SpawnRate;
Instantiate(ChooseRobot(), transform.position, Quaternion.identity);
}
}
And this is the code for choosing the robot.
public GameObject ChooseRobot() { int randomNumber = (int)Random.Range(0, robots.Count - 1); return robots[randomNumber]; }
So how can I set the robots to be a child of the player once their spawned with my current set up? Please help.
Comment