-
Notifications
You must be signed in to change notification settings - Fork 0
/
PressHammer.cs
57 lines (54 loc) · 1.72 KB
/
PressHammer.cs
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
using UnityEngine;
//! This class handles animation of the hammer and piston of a press.
public class PressHammer : MonoBehaviour
{
public GameObject press;
private StateManager stateManager;
public float originalYposition;
bool movingDown = true;
bool movingUp;
bool soundPlayed;
//! Start is called before the first frame update.
public void Start()
{
stateManager = FindObjectOfType<StateManager>();
originalYposition = transform.position.y;
}
//! Update is called once per frame.
public void Update()
{
if (!stateManager.Busy())
{
if (press.GetComponent<Light>().enabled == true)
{
if (transform.position.y > originalYposition - 0.4f && movingDown == true)
{
if (soundPlayed == false)
{
press.GetComponent<AudioSource>().Play();
soundPlayed = true;
}
transform.position -= transform.up * 0.3f * Time.deltaTime;
}
else
{
movingUp = true;
movingDown = false;
}
if (transform.position.y <= originalYposition && movingUp == true)
{
if (soundPlayed == true)
{
soundPlayed = false;
}
transform.position += transform.up * 0.3f * Time.deltaTime;
}
else
{
movingUp = false;
movingDown = true;
}
}
}
}
}