-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarModelRotator.cs
57 lines (57 loc) · 1.67 KB
/
CarModelRotator.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
using System.Collections;
using UnityEngine;
#pragma warning disable 0219
#pragma warning disable 0414
public class CarModelRotator : MonoBehaviour {
private float _sensitivity;
private Vector3 _mouseReference;
private Vector3 _mouseOffset;
private Vector3 _rotation;
private bool oneTime = true;
public bool rotating = true;
void Start () {
_sensitivity = 0.4f;
_rotation = Vector3.zero;
StartCoroutine (Rotate ());
}
public void RotateCar () {
StartCoroutine (Rotate ());
}
void Update () {
/* if (Input.GetMouseButton (0)) {
broken = true;
oneTime2 = true;
if (oneTime == true) {
oneTime = false;
_mouseReference = Input.mousePosition;
}
// offset
_mouseOffset = (Input.mousePosition - _mouseReference);
// apply rotation
_rotation.z = (_mouseOffset.x + _mouseOffset.y) * _sensitivity;
// rotate
transform.Rotate (_rotation);
// store mouse
_mouseReference = Input.mousePosition;
} else {
oneTime = true;
if (oneTime2 == true) {
broken = false;
StartCoroutine (Rotate ());
oneTime2 = false;
}
}*/
}
void OnMouseDown () {
// store mouse
_mouseReference = Input.mousePosition;
}
IEnumerator Rotate () {
rotating = true;
//transform.eulerAngles = zero;
while (rotating) {
transform.Rotate (0, 0, -1f, Space.Self);
yield return new WaitForFixedUpdate ();
}
}
}