|
| 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 | +} |
0 commit comments