forked from renaissanceCoder/Simple-Scripting-Series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotater.cs
44 lines (35 loc) · 1.11 KB
/
Rotater.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotater : MonoBehaviour {
public enum ROTATIONAXIS {
xAxis,
yAxis,
zAxis
}
public float maxRotationAngle;
public float period;
float myTime;
public ROTATIONAXIS rotationAxis;
// Update is called once per frame
void FixedUpdate () {
if(rotationAxis == ROTATIONAXIS.xAxis)
{
myTime += Time.deltaTime;
float phase = Mathf.Sin(myTime / period);
transform.localRotation = Quaternion.Euler(new Vector3(phase * maxRotationAngle,0,0));
}
else if (rotationAxis == ROTATIONAXIS.yAxis)
{
myTime += Time.deltaTime;
float phase = Mathf.Sin(myTime / period);
transform.localRotation = Quaternion.Euler(new Vector3(0, phase * maxRotationAngle, 0));
}
else if (rotationAxis == ROTATIONAXIS.zAxis)
{
myTime += Time.deltaTime;
float phase = Mathf.Sin(myTime / period);
transform.localRotation = Quaternion.Euler(new Vector3(0, 0, phase * maxRotationAngle));
}
}
}