I have a script that allows the player to spawn bullets
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShootBullet : MonoBehaviour {
public GameObject Bullet;
public Transform Kamera;
public new bool Instantiate;
public float ReloadTime;
public Text ReloadingText;
private void Start()
{
Instantiate = true;
}
void Update () {
if (Input.GetButtonDown("Fire1"))
{
if (Instantiate == true)
{
StartCoroutine(Reload());
Instantiate(Bullet, Kamera.position, Kamera.rotation);
ReloadingText.enabled = true;
}
}
}
IEnumerator Reload(){
Instantiate = false;
yield return new WaitForSeconds(ReloadTime);
Instantiate = true;
ReloadingText.enabled = false;
}
}
It works fine until I restart the level (of course I have a script for this). When the level is restarted it only does it once. It also does once if I start the game from another scene. For example, I started the game from the main menu and when I load this level from a button it only spawned once.