Pendulum.cs 492 B

123456789101112131415161718192021
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Pendulum : MonoBehaviour {
  4. public Transform pivot;
  5. public float speed = 0.5f;
  6. private float startAngle = 90.0f;
  7. private float endAngle = -90.0f;
  8. private float fTimer = 0.0f;
  9. private Vector3 v3T = Vector3.zero;
  10. void Update()
  11. {
  12. float f = (Mathf.Sin(fTimer * speed - Mathf.PI / 2.0f) + 1.0f) / 2.0f;
  13. v3T.Set(0.0f, 0.0f, Mathf.Lerp(startAngle, endAngle, f));
  14. pivot.eulerAngles = v3T;
  15. fTimer += Time.deltaTime;
  16. }
  17. }