-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtruderPiston.cs
67 lines (63 loc) · 2.14 KB
/
ExtruderPiston.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
58
59
60
61
62
63
64
65
66
67
using UnityEngine;
public class ExtruderPiston : MonoBehaviour
{
public GameObject extruder;
private StateManager stateManager;
private Vector3 originalPosition;
private Vector3 endPosition;
private bool setEndPosition;
private bool movingForward = true;
private bool movingBack;
private bool soundPlayed;
//! Called by unity engine on start up to initialize variables.
public void Start()
{
stateManager = FindObjectOfType<StateManager>();
originalPosition = transform.position;
}
//! Called once per frame by unity engine.
public void Update()
{
if (!stateManager.Busy())
{
if (extruder.GetComponent<Light>().enabled == true)
{
float startDistance = Vector3.Distance(transform.position, originalPosition);
if (startDistance < 1.2f && movingForward == true)
{
if (soundPlayed == false)
{
extruder.GetComponent<AudioSource>().Play();
soundPlayed = true;
}
transform.position += transform.right * 1.1f * Time.deltaTime;
}
else
{
if (setEndPosition == false)
{
endPosition = transform.position;
setEndPosition = true;
}
movingBack = true;
movingForward = false;
}
float endDistance = Vector3.Distance(transform.position, endPosition);
if (endDistance < 1.2f && movingBack == true)
{
if (soundPlayed == true)
{
soundPlayed = false;
}
transform.position -= transform.right * 1.1f * Time.deltaTime;
}
else
{
setEndPosition = false;
movingBack = false;
movingForward = true;
}
}
}
}
}