-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRotToRot.cs
More file actions
49 lines (41 loc) · 1.33 KB
/
RotToRot.cs
File metadata and controls
49 lines (41 loc) · 1.33 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotToRot : MonoBehaviour
{
[SerializeField] private Vector3 _TargetAngle = new Vector3(0f, 0f, 0f);
[Header("Settings")]
[SerializeField] private float _Speed = 1;
[SerializeField] private bool _Lerp = true;
[SerializeField] private bool _OnStart = false;
private bool _Activated;
private Vector3 _CurrentAngle;
void Start()
{
_CurrentAngle = transform.localEulerAngles;
if(_OnStart)
StartRotating();
}
void Update()
{
if (_Activated)
{
if (_Lerp)
{
_CurrentAngle = new Vector3(
Mathf.LerpAngle(_CurrentAngle.x, _TargetAngle.x, _Speed * Time.deltaTime),
Mathf.LerpAngle(_CurrentAngle.y, _TargetAngle.y, _Speed * Time.deltaTime),
Mathf.LerpAngle(_CurrentAngle.z, _TargetAngle.z, _Speed * Time.deltaTime));
}
else
{
_CurrentAngle = Vector3.MoveTowards(_CurrentAngle, _TargetAngle, _Speed * Time.deltaTime);
}
transform.localEulerAngles = _CurrentAngle;
}
}
public void StartRotating()
{
_Activated = true;
}
}