- Home /
Spawning random location
Hi, I am trying to make a system, where dynamite can spawn in 3 places, but its random at which one it spawns. I used an random float generator and depending on which number it gives me, the dynamite will get an spawnpoint assigned. However, when I try to run my game, the dynamite just stays where I placed it. The code:
public Transform Spawnpoint1;
public Transform Spawnpoint2;
public Transform Spawnpoint3;
public Transform Dynamite;
void Start()
{
float Location = Random.Range(1, 3);
if (Location == 1)
{
Dynamite = Spawnpoint1;
}
if(Location == 2)
{
Dynamite = Spawnpoint2;
}
else
{
Dynamite = Spawnpoint3;
}
}
Answer by Harry_Drew · Apr 17, 2021 at 04:43 PM
@lucashahne06 Try: Dynamite.position = Spawnpoint1.position.
Your answer
Follow this Question
Related Questions
How to spawn cubes on mouse position 1 Answer
UNET: PlayerPrefab's `Start()` is being called before play scene's `Awake()` 0 Answers
Instantiating unique Prefabs to unique child objects in C# 3 Answers
How to respawn player car in war track 1 Answer
Spawning 2 players at the start of the game when it should not 0 Answers