OK, my FPS is coming along slowly but Ive hit a problem. I have sliding doors in my game that work fine using triggers BUT now I want to add a key so that certain doors will only open if the player has this key.
Im using one very basic script called ‘playerInventory’ which has a Boolean variable called ‘hasKey’
(I have this attached to my player)
My other script is attached to the key itself -
var pickUp : AudioClip;
var hasKey : boolean;
function OnTriggerEnter ()
{
AudioSource.PlayClipAtPoint(pickUp, transform.position);
hasKey = true;
Destroy(gameObject);
}
For the main part all works well, key is destroyed on contact with trigger, sound plays and object gets destroyed.
My problem is that as soon as the object is destroyed the ‘hasKey’ variable doesn’t exist. How do I get the variable from this script to be recognised by my playerInventory script?