So I was making a game project for my subject game design 2, it is a space shooter game. After completing it all, I tried playing it. It works fine as I expected but then when I tried to play it again, after pressing play when I hover my mouse to the start button. I can’t click it anymore, I can’t shoot the bullets from my space ship and the movement on my enemies won’t initiate since I have put a condition in that script that the enemy movement and shooting of my ship will only work after I clicked the start button.
I already double checked all my scripts and there were no errors or what. I tried importing it all again and restarting unity it’s still the same. It’s a 50/50 chance of it letting me click it all the way to the 3 scenes or levels I made.
Here is the script for my UI
using UnityEngine;
public class UIManager : MonoBehaviour
{
bool checkStart;
bool startEnemyMovement;
bool buttonClicked;
void Start()
{
checkStart = false;
startEnemyMovement = false;
buttonClicked = false;
// disable the enemyscript so that the enemy won't move immediately
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<EnemyScript>().enabled = false;
}
}
private void FixedUpdate()
{
if (startEnemyMovement && buttonClicked)
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<EnemyScript>().enabled = true;
}
startEnemyMovement = false;
buttonClicked = false;
}
}
private void OnGUI()
{
if (!checkStart)
{
GUI.Box(new Rect(310, 100, 300, 200), "SPACE SHOOTER");
// Create a "START" button
if (GUI.Button(new Rect(382, 150, 150, 50), "START"))
{
startEnemyMovement = true;
checkStart = true;
buttonClicked = true;
// enable the ship to shoot when the "START" button is clicked
GameObject playerShip = GameObject.FindGameObjectWithTag("Player");
if (playerShip != null)
{
MyShipBulletScript shipBulletScript = playerShip.GetComponent<MyShipBulletScript>();
if (shipBulletScript != null)
{
shipBulletScript.EnableFiring();
}
}
}
// Create an "EXIT" button
if (GUI.Button(new Rect(382, 220, 150, 50), "EXIT"))
{
checkStart = true;
}
}
}
}