It’s kind of difficult to answer you question, as it is a design question, and without a better understanding of the system all I can give you is some best practice pointers.
A static variable is a variable which lives outside the context of an instance. For example, the constant PI, or any of the Mathf class methods. None of those things are logically related to a single instance of Mathf.
In your case however, a door’s lock state can be definitely tied to an instnace, or a specific door. Consider this, you have your Door class, this class defines “a door”. However, if you want to define a specific door, you’ll refer to it’s instance rather than it’s class - “the blue door is a door”, the which is answered by “the blue door” - the instance, while the what is answered by “a door” - the class.
In such case, defining unlockDoor as static is wrong, and bad, because you’re using a static variable as a global, which is what get’s people really worked over.
A better definition would be like so:
A door can be either locked or unlocked. A locked door is opened using a specific key:
class Door
{
bool isLocked;
string keyType;
}
The player has a keyring, which holds all of his keys:
class Player
{
Keyring doorKeys;
}
A keyring holds all of the keys the player has acquired. A keyring can be checked to see if it contains a required key:
class Keyring
{
string[] keys;
bool HasKey( string keyType );
}
When the player reaches a door, he checks the lock type on the door ( it’s a blue door lock, it’s a small door lock, etc… ), he then checks his keyring for the appropriate key, and if his keyring contains the right key, he will use it to unlock the door:
OnTriggerEnter( Collider other )
{
Door door = other.GetComponent< Door >();
// Make sure the trigger is actually a door trigger
if ( door != null )
{
string keyType = door.keyType; // Check the door's key type
if ( keyring.HasKey( keyType ) )
{
door.Unlock()
}
}
}