-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockRotation.cs
More file actions
60 lines (48 loc) · 1.31 KB
/
ClockRotation.cs
File metadata and controls
60 lines (48 loc) · 1.31 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClockRotation : MonoBehaviour, IUseable
{
public float rotationSpeed = 1f;
private bool canRotate = false;
public int clock;
//private bool onRotation = false;
Quaternion targetRot;
public void Use()
{
canRotate = true;
targetRot = transform.rotation * Quaternion.Euler(0f, 30f, 0);
}
// Update is called once per frame
void Update()
{
if (canRotate)
{
if (clock == 12)
{
clock = 1;
}
else
{
clock += 1;
}
StartCoroutine(Rotate());
canRotate = false;
}
}
IEnumerator Rotate()
{
this.gameObject.GetComponent<Collider>().enabled = false;
float elapsedTime = 0f;
Quaternion startingPos = transform.rotation;
while (elapsedTime < rotationSpeed)
{
transform.rotation = Quaternion.Lerp(startingPos, targetRot, elapsedTime / rotationSpeed);
elapsedTime += Time.deltaTime;
yield return null;
}
transform.rotation = targetRot;
Debug.Log(clock);
this.gameObject.GetComponent<Collider>().enabled = true;
}
}