So, I’ve been searching for a solution for some time, and have found a lot of similar posts with slightly different errors, so I will get out of the way that A) I have not disabled the gameobject, or parent of the gameobject in which the script is contained, and B) I am not using .Find(“Name”) or something of the like to reference my gameobject - it is declared as a public variable and asigned in the inspector.
My Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Equip : MonoBehaviour
{
public GameObject item;
public GameObject holster;
private bool itemHolstered;
private void unHolster()
{
item.SetActive(true);
holster.SetActive(false);
itemHolstered = false;
}
private void Holster()
{
item.SetActive(false);
holster.SetActive(true);
itemHolstered = true;
}
// Start is called before the first frame update
void Start()
{
Holster();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(“x”))
{
if (itemHolstered == false)
{
unHolster();
}
else if (itemHolstered == true)
{
Holster();
}
}
}
}
The gameobjects being assigned in the inspector:
And the gameobjects in the hierarchy - Note Equip is the gameobject to which the script is attached
Any help would be greatly apreciated as I am thoroughly stumpted.