Skip to content

Commit 46d8d75

Browse files
committed
Add new RotateAround script
1 parent 5bbe93a commit 46d8d75

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Runtime/RotateAround.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEngine;
2+
3+
namespace Zigurous.Animation
4+
{
5+
/// <summary>
6+
/// Rotates an object around a point by a given speed.
7+
/// </summary>
8+
public sealed class RotateAround : MonoBehaviour
9+
{
10+
/// <summary>
11+
/// The point to rotate around.
12+
/// </summary>
13+
[Tooltip("The point to rotate around.")]
14+
public Transform point;
15+
16+
/// <summary>
17+
/// The axis in which the object rotates.
18+
/// </summary>
19+
[Tooltip("The axis in which the object rotates.")]
20+
public Vector3 axis = Vector3.up;
21+
22+
/// <summary>
23+
/// The speed at which the object rotates.
24+
/// </summary>
25+
[Tooltip("The speed at which the object rotates.")]
26+
public float speed = 1.0f;
27+
28+
/// <summary>
29+
/// The update mode during which the object rotates.
30+
/// </summary>
31+
[Tooltip("The update mode during which the object rotates.")]
32+
public UpdateMode updateMode = UpdateMode.Update;
33+
34+
private void Update()
35+
{
36+
if (this.point != null && this.updateMode == UpdateMode.Update) {
37+
this.transform.RotateAround(this.point.position, this.axis, this.speed * Time.deltaTime);
38+
}
39+
}
40+
41+
private void LateUpdate()
42+
{
43+
if (this.point != null && this.updateMode == UpdateMode.LateUpdate) {
44+
this.transform.RotateAround(this.point.position, this.axis, this.speed * Time.deltaTime);
45+
}
46+
}
47+
48+
private void FixedUpdate()
49+
{
50+
if (this.point != null && this.updateMode == UpdateMode.FixedUpdate) {
51+
this.transform.RotateAround(this.point.position, this.axis, this.speed * Time.fixedDeltaTime);
52+
}
53+
}
54+
55+
}
56+
57+
}

Runtime/RotateAround.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)