-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotDoorOpen.cs
60 lines (48 loc) · 1.28 KB
/
dotDoorOpen.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class dotDoorOpen : MonoBehaviour
{
public GameObject leftDoor;
public GameObject rightDoor;
[SerializeField] private AudioClip[] doorSound;
private AudioSource audioSource;
public bool DoorIsOpen;
void Start(){
audioSource = GetComponent<AudioSource>();
}
public void OpenDoor()
{
if (!DoorIsOpen)
{
audioSource.clip = doorSound[0];
audioSource.PlayOneShot(audioSource.clip);
leftDoor.transform.DOLocalMoveZ(-5.69f, 3.5f).SetEase(Ease.OutBack);
rightDoor.transform.DOLocalMoveZ(2.64f, 3.5f).SetEase(Ease.OutBack);
DoorIsOpen = true;
}
}
public void CloseDoor()
{
if (DoorIsOpen)
{
audioSource.clip = doorSound[1];
audioSource.PlayOneShot(audioSource.clip);
leftDoor.transform.DOLocalMoveZ(-3.09f, 3.5f);
rightDoor.transform.DOLocalMoveZ(-0.072f, 3.5f);
DoorIsOpen = false;
}
}
public void ToggleDoor()
{
if (DoorIsOpen)
{
Invoke("CloseDoor", 4.0f);
}
else
{
OpenDoor();
}
}
}