Answer the question
In order to leave comments, you need to log in
Why is there no delay in my code and objects are created immediately?
No delay, objects are created immediately.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cube : MonoBehaviour
{
// Start is called before the first frame update
public GameObject obj;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.F))
{
StartCoroutine(inst());
}
}
IEnumerator inst()
{
while (true)
{
Instantiate(obj, new Vector3(0f, Random.Range(-10f, 10f), 0f), Quaternion.identity);
yield return new WaitForSeconds(1.0f);
}
}
}
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