I am trying to make a door that should recognize if the player has taken up the key in the area. the key is a simple trigger collision makes a bool be true.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Key"))
{
other.gameObject.SetActive(false);
hasKey = true;
Debug.Log(hasKey);
}
}
while the door checks this script on its trigger.
void OnTriggerEnter()
{
if (RequiresKey == true)
{
if (_fpsCharacterController.hasKey == true)
{
if (onTriggerEnterParameterName != null)
{
Debug.Log("You have the key");
animator.SetTrigger(onTriggerEnterParameterName);
}
}
else if (_fpsCharacterController.hasKey == false)
{
Debug.Log("you don't have the key");
}
}
else if (RequiresKey == false)
{
if (onTriggerEnterParameterName != null)
{
animator.SetTrigger(onTriggerEnterParameterName);
}
}
}
The Bool is public and when i manually change it on the players prefab the door works, bur it doesn’t work when i take up the key in the game.