I was following a tutorial to make a key open a door to lead to the end of the game/the next level, but I can’t physically pick up the key to an inventory and therefore I can’t open the door. These are the scripts I’m using:
Door Script -
var Key : GameObject;
private var Door = false;
function Start ()
{
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.E) && Door == true && Key.active == false)
{
Application.LoadLevel("NextLevel");
}
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Door = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Door = false;
}
}
Key Script -
var TheKey : GameObject;
private var playerNextToKey = false;
function Update ()
{
if (Input.GetKeyDown(KeyCode.E) && playerNextToKey == true)
{
TheKey.active = false;
}
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
playerNextToKey = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
playerNextToKey = false;
}
}
Please can someone tell me how to physically pick up the key so that I can then unlock the door to either end the game (preferably) or lead to the next level.
HELP NEEDED ASAP, THIS GAME HAS A DEADLINE!