F3DWarpTunnel.cs 767 B

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. using System.Collections;
  3. public class F3DWarpTunnel : MonoBehaviour {
  4. public float MaxRotationSpeed;
  5. public float AdaptationFactor;
  6. float speed, newSpeed;
  7. // Use this for initialization
  8. void Start () {
  9. speed = 0;
  10. OnDirectionChange();
  11. }
  12. void OnDirectionChange()
  13. {
  14. newSpeed = Random.Range(-MaxRotationSpeed, MaxRotationSpeed);
  15. F3DTime.time.AddTimer(Random.Range(1, 5), 1, OnDirectionChange);
  16. }
  17. // Update is called once per frame
  18. void Update () {
  19. speed = Mathf.Lerp(speed, newSpeed, Time.deltaTime * AdaptationFactor);
  20. transform.rotation = Quaternion.Lerp(transform.rotation, transform.rotation * Quaternion.Euler(speed, 0, 0), Time.deltaTime);
  21. }
  22. }