Hello,
I am having a little dilemma. I am working on a game and I have pretty much everything set UI wise. It’s a neat 1st Person Puzzle/Adventure game I’ve been working on. I have keys, they have scripts, and once the player goes through the onTriggerEnter, the key disappears, a bool (hasKey) goes true, and a keyCount increments by one.
That’s the easy part. The hard part is trying to use the newly-gathered key to open a door automatically. I have the door a cube, I have a box collider, marked it as isTrigger, and gave it a RigidBody (like the key, btw).
Here’s the awesome part, I think this is a Unity deal (correct me if I’m wrong), but it seems that every object that is isTrigger true, the player can pass right through it. This makes it a pain due to the fact that I would rather have it so that the key opens the door (and the player does NOT pass through the door as if it was some sort of ghost door).
I have been looking EVERYWHERE to try to figure out a working fix for this, but I’m not coming up with anything that works. Could I ask for some help, please?
I am attaching a code to the door so that the door handles all the necessary leg-work (as it would make more sense since the door will have the RigidBody component). Thanks, again, for any help.
using UnityEngine;
using System.Collections;
public class DoorTrigger : MonoBehaviour {
void OnTriggerEnter(Collider other){
if (Timer.hasKey && Timer.keyCount > 0){
collider.isTrigger = true;
Destroy(gameObject);
Timer.keyCount--;
}
//if keyCount == 0
//Do nothing
if (Timer.keyCount <= 0){
}
}
}