1234567891011121314151617181920212223242526272829 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RotateJoint : MonoBehaviour
- {
- Rigidbody m_Rigidbody;
- Vector3 m_EulerAngleVelocity;
- float timer = 5;
- float defaultTimer = 5;
- void Start()
- {
- m_EulerAngleVelocity = new Vector3(20,20,20);
- m_Rigidbody = GetComponent<Rigidbody>();
- }
- void FixedUpdate()
- {
- timer -= Time.deltaTime;
- if(timer < 0)
- {
- m_EulerAngleVelocity = -m_EulerAngleVelocity;
- timer = defaultTimer;
- }
-
- Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.deltaTime);
- m_Rigidbody.MoveRotation(m_Rigidbody.rotation * deltaRotation);
- }
- }
|