- Home /
Doesn't spawn when level is restarted
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.
Try putting debug.logs and see where it stops. Also "$$anonymous$$amera" is spelled Camera
It doesn't set Instantiate to true again. What should I do?
$$anonymous$$aybe ReloadTime is too long, and so the WaitForSeconds is waiting forever
Answer by Zymurer · Dec 14, 2018 at 02:55 PM
I think I got the problem but cannot try it because I figured it out after deleting the project. I forgot to set the time scale to 1 again.