Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- [ExecuteInEditMode]
- public class EditorRotationScript : MonoBehaviour
- {
- [SerializeField]
- private float m_rotationRadius = 1f;
- [SerializeField]
- [Range(-300.0f, 300.0f)]
- private float m_rotationSpeed = 1f;
- private double m_lastTime = 0f;
- private Vector3 m_oP;
- private Quaternion m_oR;
- private float m_currentRotation = 0f;
- private void OnEnable()
- {
- EditorApplication.update += Update;
- m_lastTime = EditorApplication.timeSinceStartup;
- m_oP = transform.position;
- m_oR = transform.rotation;
- m_currentRotation = 0f;
- }
- private void OnDisable()
- {
- EditorApplication.update -= Update;
- transform.position = m_oP;
- transform.rotation = m_oR;
- }
- private void Update()
- {
- double delta = EditorApplication.timeSinceStartup - m_lastTime;
- m_lastTime = EditorApplication.timeSinceStartup;
- m_currentRotation += (float)(m_rotationSpeed * delta);
- transform.position = new Vector3(m_oP.x + m_rotationRadius * Mathf.Cos(m_currentRotation), m_oP.y, m_oP.z + m_rotationRadius * Mathf.Sin(m_currentRotation));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement