I’m trying to instantiate just one prefab inside the method udpate, but the thing is, it’s instantiating twice. I don’t know how I could solve this problem.
What could I do? I’ve created a boolean called spawned, but it’s not working.
public class SpawnaCasos : MonoBehaviour
{
public GameObject[] Casos;
private GameController gameController;//variável para acessar o script do gamecontroller
private GameObject controller;
private bool spawned = false;
// Start is called before the first frame update
void Start()
{
controller = GameObject.FindGameObjectWithTag("Controller");
gameController = controller.GetComponent<GameController>();
}
// Update is called once per frame
void Update()
{
if (gameController.contadorPontos == 14 && spawned == false)
{
Instantiate(Casos[UnityEngine.Random.Range(0, 8)], transform.position, this.transform.rotation);
spawned = true;
}
}
}