Hello, I’m creating a network multiplayer car game and i’m blocked by this issue of assigning checkpoint transforms to a cloned car.
Let me explain it more so as to make it more clear, I have created cube as checkpoints and they are present in the hierarchy as CheckPoint1, CheckPoint2 etc… Now once i start the game, i need to assign these checkpoints to a script attached to the cloned or instantiated prefab… Any help would be very helpful.
GameObject.Find(“Checkpoint1”) will find an object named Checkpoint1 in the scene. I’m not sure if it checks inside object; you might want to make all your checkpoints the child of “CheckpointFolder” and then use GameObject.Find(“CheckpointFolder/Checkpoint”+index).
Let me see if I understand. You have cubes as checkpoints along the racetrack, and need a script(attached to a clone) to get their transforms?
Try declaring a public GameObject checkpoint1, checkpoint2;
Then, from the editor, select the script on the assets tab. On the top of the Inspector tab, your checkpoints should appear. Assign the cubes to these so that the script will default to them. Then, simply attach the script to the clone car prefab. When instantiated, the clone should have the script attached, and the checkpoints should default to the right cubes.