Idk how to make a script wait like you can in the c# virtual studio console and when I try to load my script from what I could gather infinite loops crash unity. I think coroutines do something but I don’t understand them. Could you help me find how to fix my script and explain how the Wait part of the script works ;-;
using UnityEngine;
using System.Collections;
public class CannonScript : MonoBehaviour {
GameObject prefab;
public GameObject Cannon;
public GameObject Bullet;
public float Bullet_Foward_Force;
void Start ()
{
}
void Update ()
{
for (int i = 0; i < 10; i++ )
{
GameObject temporary_Bullet_handler = Instantiate(Bullet, Cannon.transform.position, Cannon.transform.rotation) as GameObject;
Rigidbody Temporary_Rigidbody;
Temporary_Rigidbody = temporary_Bullet_handler.GetComponent();
Temporary_Rigidbody.AddForce(transform.forward * Bullet_Foward_Force);
//I want to have a script wait here
Destroy(temporary_Bullet_handler, 10.0f);
}
}
}