Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections.Generic; 3.
4. public class GeneralDoor : MonoBehaviour { 5.
6.
//Is the door initially open?
7.
public bool initiallyOpen = false;
8.
9.
//Key to unlock the door
10.
public
string
unlockKey;
11.
12.
//Internal state storage
13.
bool isOpen;
14.
15.
//Internal state of lock
16.
bool
locked; 17.
18.
void Start () {
19.
//Lock the door if there is an unlock key provided
20.
locked = !string.IsNullOrEmpty(unlockKey);
21.
//Set the initial state of the door
22.
isOpen = initiallyOpen;
23.
}
24.
25.
void Update () { 26.
27.
}
28.
29.
//Open the door if not locked
30.
public void Open(){
31.
if(!locked){
32.
isOpen = true;
33.
}
34.
}
35.
36.
//Close the door if not locked
37.
public void Close(){
Search WWH ::




Custom Search