RotateTester.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RotateTester : MonoBehaviour
  5. {
  6. public GameObject subject;
  7. public bool locking = false;
  8. public bool lockX;
  9. public bool lockY;
  10. public bool lockZ;
  11. Vector3 savedRotation;
  12. bool needToSave = true;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if(locking){
  21. if(needToSave){
  22. savedRotation = subject.transform.localEulerAngles;
  23. needToSave = false;
  24. }
  25. Vector3 inverseRot = Quaternion.Inverse(subject.transform.localRotation).eulerAngles;
  26. transform.rotation = Quaternion.identity;
  27. transform.position = new Vector3(0,0,0);
  28. //transform.rotation = (Quaternion.Inverse(subject.transform.localRotation));
  29. // transform.RotateAround(subject.transform.position, new Vector3(1,0,0), inverseRot.x);
  30. transform.RotateAround(subject.transform.position, new Vector3(0,1,0), inverseRot.y);
  31. //inverseRot = Quaternion.Inverse(subject.transform.localRotation).eulerAngles;
  32. //transform.RotateAround(subject.transform.position, new Vector3(0,0,1), inverseRot.z);
  33. //transform.RotateAround(subject.transform.position, new Vector3(1,0,0), savedRotation.x);
  34. transform.RotateAround(subject.transform.position, new Vector3(0,1,0), savedRotation.y);
  35. //inverseRot = Quaternion.Inverse(subject.transform.localRotation).eulerAngles;
  36. //transform.RotateAround(subject.transform.position, new Vector3(0,0,1), savedRotation.z);
  37. }
  38. }
  39. }