I am making a 2D football themed game and I have currently set up 3 spawn points for a gameobject, a redcard. Whenever the football hits the randomly spawned redcard, it contributes -3 to my score. However, based on the code i have, multiple redcards spawn at a single spawn point and they spawn on top of each other. so when the ball hits that spawn point, all the overlapping red cards activate and my score plummets. I only want ONE red card at a specific spawn point. And i also would like for the red card to disappear after a certain amount of time after its spawned. I am very new to game development so your help is really appreciated. Thanks in advance. Here is my code. Redcard is the prefab. All of this works so far. its just the rest i need help with.
var timer : float = 0.0;
var spawning : boolean = false;
var prefab : Rigidbody;
var spawn1 : Transform;
var spawn2 : Transform;
var spawn3 : Transform;
function Update () {
if(!spawning){
timer += Time.deltaTime;
}
if(timer >= 2){
Spawn();
}
}
function Spawn(){
spawning = true;
timer = 0;
var randomPick : int = Mathf.Abs(Random.Range(1,4));
var location : Transform;
if(randomPick == 1){
location = spawn1;
Debug.Log("Chose pos 1");
}
else if(randomPick == 2){
location = spawn2;
Debug.Log("Chose pos 2");
}
else if(randomPick == 3){
location = spawn3;
Debug.Log("Chose pos 3");
}
yield WaitForSeconds(1);
spawning = false;
}