So I fixed the error in my last line of code, but now I have another problem. This script is supposed to allow the Player to collect a key. Then, the Player is supposed to enter a trigger and click to open a door. However, the Player can open the door now without collecting the key. Here are the scripts: Can someone tell me what I did wrong?
Key Script - Attached to Player
var keyObject : GameObject;
var keypickup : AudioClip;
var inRange;
public var Door : GameObject;
public var Locked : GameObject;
function OnTriggerEnter(Other : Collider) {
if(Other.gameObject.tag == ("key"))
{
inRange = true;
}
}
function OnTriggerExit(Other : Collider) {
if(Other.gameObject.tag == ("key"))
{
inRange = false;
}
}
function OnTriggerStay() {
if(Input.GetButton("Fire1") && inRange == true)
{
Debug.Log("Key has been collected");
audio.clip = keypickup;
audio.Play();
Destroy (keyObject);
key();
}
}
function key()
{
Door.GetComponent("Door").enabled = true;
Locked.GetComponent("Locked").enabled = false;
}
Door Script - Attached to Door
function OnTriggerStay() {
if(Input.GetButtonDown ("Fire1"))
{
door();
}
}
function door() {
animation.Play("open01");
debug();
}
function debug() {
if(Input.GetButtonDown ("Fire1"))
{
Debug.Log("Door");
}
}
Locked Door Script - Attached to Door
var AudioFile : AudioClip;
function OnTriggerStay() {
if(Input.GetButtonDown ("Fire1"))
{
audio.clip = AudioFile;
audio.Play();
}
}
I made sure the door script was unchecked when I ran the game, but no use.