-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrownDoor.cs
More file actions
69 lines (55 loc) · 1.71 KB
/
brownDoor.cs
File metadata and controls
69 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using UnityEngine;
public class brownDoor : MonoBehaviour
{
private stageControl stageControlScript; // access the stage control script
[SerializeField] private Transform openPosition; // Position where the door moves down to
[SerializeField] private Transform closedPosition; // Position where the door moves up to
[SerializeField] private float speed = 1.0f; // Speed of the door's movement
private bool isOpening = false;
private bool isClosing = false;
private bool hasOpened = false;
private void Awake()
{
stageControlScript = GetComponent<stageControl>();
}
private void openDoor()
{
// open door
hasOpened = true;
isOpening = true;
isClosing = false;
}
public void closeDoor()
{
// close door
isOpening = false;
isClosing = true;
}
// Update is called once per frame
void Update()
{
if (stageControlScript.stageComplete && !hasOpened)
{
openDoor();
}
if (isOpening)
{
transform.position = Vector3.MoveTowards(transform.position, openPosition.position, speed * Time.deltaTime);
// move down
if (transform.position == openPosition.position)
{
isOpening = false;
// the door has opened
}
}
if (isClosing)
{
// move up
transform.position = Vector3.MoveTowards(transform.position, closedPosition.position, speed * Time.deltaTime);
if (transform.position == closedPosition.position)
{
isClosing = false;
} // door has closed
}
}
}