Answer the question
In order to leave comments, you need to log in
Why does object spawning work incorrectly?
Hello everyone, I'm trying to spawn objects when the character is on the ground. I'm trying to implement this through "Coroutine", but the objects spawn very quickly, a few per second, I think. The time limiter is worth it. What to do?
public GameObject enemy;
public PlayerMovement PlayerMovementScript;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
StartCoroutine(da());
}
IEnumerator da()
{
while (PlayerMovementScript.isGrounded == true)
{
Instantiate(enemy, new Vector3(Random.Range(-30, 30), 1f, Random.Range(-30, 30)), Quaternion.identity);
yield return new WaitForSeconds(3f);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question