How do I use multiple trigger functions in one scene
I am trying to do a basic key and door thing. The user (sphere) rolls into the key, and removes it like I want. But then if it hits the door, the door won't be removed like I want. At the moment I've just set a variable to change when the key is gone, and only with the changed value can the door be "opened", but it never gets removed. Any help? There's no errors from the system so I'm not sure what I have to do to make it work. Everything involved has a collider, and I've tried both putting the key and door as triggers, and just the player being the trigger, but the same issue happens every time.
void OnTriggerEnter(Collider col)
{
bool haveKey = false;
if (col.gameObject.name == "Key")
{
haveKey = true;
Destroy (col.gameObject);
}
if (col.gameObject.name == "Door")
{
if (haveKey == true)
{
Destroy (col.gameObject);
}
}
}
Answer by PowerGrainger · Apr 13, 2018 at 11:28 AM
I have found a solution where I have used OnCollisionEnter for the door and trigger for the key and this seems to work. If anyone does still have the answer for this for anyone else though it may be appreciated!