-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLift.cs
More file actions
43 lines (34 loc) · 1.15 KB
/
Lift.cs
File metadata and controls
43 lines (34 loc) · 1.15 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
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (AudioSource))]
public class Lift : MonoBehaviour, IInteractable {
public GameObject objectToMove;
public GameObject target;
public float speed = .01f;
public bool up;
public AudioClip sound;
private AudioSource _audioSource;
private bool move = false;
void Start(){
_audioSource = GetComponent<AudioSource>();
}
void FixedUpdate(){
if(move && objectToMove.transform.position != target.transform.position)
objectToMove.transform.position = Vector3.Lerp(objectToMove.transform.position, target.transform.transform.position, speed);
if(Vector3.Distance(objectToMove.transform.position, target.transform.position) < .5f)
move = false;
}
public void OnInteract(){
if(sound != null)
_audioSource.PlayOneShot(sound);
move = true;
// Vector3 waterLevel = objectToMove.transform.position;
// if(up)
// objectToMove.transform.position = new Vector3(waterLevel.x, waterLevel.y+1, waterLevel.z);
// else
// objectToMove.transform.position = new Vector3(waterLevel.x, waterLevel.y-1, waterLevel.z);
}
public GameObject GetGameObject(){
return gameObject;
}
}