subere23

Rotations

Nov 14th, 2017
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Rotations : MonoBehaviour {
  6.  
  7. public enum RotationMode { Euler, Slerp, LookRotation}
  8. public RotationMode rotationMode;
  9. public Quaternion quaternion;
  10. public float RollZ;
  11. public float PitchX;
  12. public float YawY;
  13.  
  14. public Transform lookAtSphere;
  15.  
  16. void Update()
  17. {
  18.  
  19. RollZ = transform.localRotation.eulerAngles.z;
  20. YawY = transform.localRotation.eulerAngles.y;
  21. PitchX = transform.localRotation.eulerAngles.x;
  22.  
  23. switch (rotationMode)
  24. {
  25.  
  26. case RotationMode.Euler:
  27. {
  28. transform.rotation *= Quaternion.Euler(0, 0, 0.5f);
  29. quaternion = transform.rotation;
  30. break;
  31.  
  32. }
  33. case RotationMode.Slerp:
  34. {
  35. transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0.1f,1.0f,1.0f),2f* Time.deltaTime);
  36. quaternion = transform.rotation;
  37. break;
  38. }
  39. case RotationMode.LookRotation:
  40. {
  41. transform.rotation = Quaternion.LookRotation(transform.position - lookAtSphere.position, Vector3.left);
  42. quaternion = transform.rotation;
  43. break;
  44. }
  45.  
  46. default:
  47. break;
  48.  
  49. }
  50. }
  51.  
  52. }
RAW Paste Data