123456789101112131415161718192021222324252627282930313233 |
- using UnityEngine;
- using System.Collections;
- public class ConstantRotation : MonoBehaviour
- {
- public float minRotationSpeed = 100;
- public float maxRotationSpeed = 400;
- public bool canBeNegative;
- public Transform rotationPoint;
- float _rotationSpeed;
- Transform _transform;
- static Vector3 _zAxis = new Vector3(0, 0, 1);
- void Start()
- {
- _transform = transform;
- }
- void OnEnable()
- {
- _rotationSpeed = Random.Range(minRotationSpeed, maxRotationSpeed);
- if (canBeNegative)
- {
- _rotationSpeed *= Random.value < 0.5f ? -1 : 1;
- }
- }
- void Update()
- {
- _transform.RotateAround(rotationPoint.position, _zAxis, _rotationSpeed * Time.deltaTime);
- }
- }
|