-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawer.cs
More file actions
62 lines (51 loc) · 1.32 KB
/
Drawer.cs
File metadata and controls
62 lines (51 loc) · 1.32 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
using System.Collections;
using System.Collections.Generic;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
public class Drawer : MonoBehaviour, IUseable
{
public Vector3 values;
private Vector3 drawerPos;
private bool canInteract;
private bool open;
public float openSpeed = 1f;
// Start is called before the first frame update
void Start()
{
drawerPos = transform.position;
}
// Update is called once per frame
void Update()
{
if (canInteract)
{
if (!open) //açýlma
{
StartCoroutine(MoveDrawer(drawerPos + values));
}
else //kapanma
{
StartCoroutine(MoveDrawer(drawerPos));
}
open = !open;
canInteract = false;
}
}
IEnumerator MoveDrawer(Vector3 targetPos)
{
float elapsedTime = 0f;
Vector3 startingPos = transform.position;
while (elapsedTime < openSpeed)
{
transform.position = Vector3.Lerp(startingPos, targetPos, elapsedTime / openSpeed);
elapsedTime += Time.deltaTime;
yield return null;
}
transform.position = targetPos;
}
public void Use()
{
canInteract = true;
}
}