2019-12-22 18:20:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
|
|
|
|
public class UnityRotationEvent : UnityEvent<float>
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public class RotateGameObject : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] float smooth = 5.0f;
|
|
|
|
|
[SerializeField] bool tiltAngleHorizontal;
|
|
|
|
|
[SerializeField] bool tiltAngleVertical;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private UnityRotationEvent onRotationProcessed;
|
|
|
|
|
|
|
|
|
|
private float input_;
|
|
|
|
|
|
|
|
|
|
public void OnValueChanged(float value)
|
|
|
|
|
{
|
|
|
|
|
input_ = Mathf.Repeat(input_, 360) + value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2020-01-21 22:31:06 +00:00
|
|
|
|
float tiltAroundY;
|
2019-12-22 18:20:06 +00:00
|
|
|
|
float tiltAroundX;
|
|
|
|
|
|
|
|
|
|
// Smoothly tilts a transform towards a target rotation.
|
|
|
|
|
if (tiltAngleHorizontal)
|
|
|
|
|
{
|
2020-01-21 22:31:06 +00:00
|
|
|
|
tiltAroundY = input_;
|
2019-12-22 18:20:06 +00:00
|
|
|
|
}
|
2020-01-21 22:31:06 +00:00
|
|
|
|
else tiltAroundY = 0;
|
2019-12-22 18:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tiltAngleVertical)
|
|
|
|
|
{
|
|
|
|
|
tiltAroundX = input_;
|
|
|
|
|
}
|
|
|
|
|
else tiltAroundX = 0;
|
|
|
|
|
|
|
|
|
|
|
2020-01-21 22:31:06 +00:00
|
|
|
|
Quaternion target = Quaternion.Euler(tiltAroundX , tiltAroundY, 0);
|
2019-12-22 18:20:06 +00:00
|
|
|
|
|
|
|
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|