I’m making an upgrade menu, and i’m trying to disable a script during its activation. The script is shown below.
using UnityEngine;
using System.Collections;
public class PlayerStats : MonoBehaviour {
private PlayerStats stats;
public static PlayerStats instance;
public int startingHealth = 100;
[SerializeField]
private GameObject upgradeMenu;
public delegate void UpgradeMenuCallback(bool active);
public UpgradeMenuCallback onToggleUpgradeMenu;
public int _currentHealth;
public int currentHealth
{
get { return _currentHealth; }
set { _currentHealth = Mathf.Clamp (value, 0, startingHealth); }
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.U))
{
ToggleUpgradeMenu();
}
}
private void ToggleUpgradeMenu()
{
upgradeMenu.SetActive (!upgradeMenu.activeSelf);
onToggleUpgradeMenu.Invoke(upgradeMenu.activeSelf);
}
void onUpgradeMenuToggle ()
{
GetComponent<PlayerMovement> ().enabled = false;
GetComponent<PlayerShooting> ().enabled = false;
}
void Awake()
{
if (instance == null) {
instance = this;
}
currentHealth = startingHealth;
}
}
The code I wrote for the function i’m trying to use is this:
void onUpgradeMenuToggle ()
{
GetComponent<PlayerMovement> ().enabled = false;
GetComponent<PlayerShooting> ().enabled = false;
}
Is there something I missed in the whole code, or did I just do the function wrong?