ControlTransform.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SC.XR.Unity
  5. {
  6. public class ControlTransform : MonoBehaviour
  7. {
  8. [Range(0.1f, 10f)]
  9. public float speed = 0.4f;
  10. Vector3 positionReset, eulerAnglesReset;
  11. void Awake()
  12. {
  13. this.gameObject.AddComponent<AllMoveEvent>();
  14. positionReset = transform.position;
  15. eulerAnglesReset = transform.eulerAngles;
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. #if UNITY_EDITOR
  21. if (Application.platform == RuntimePlatform.Android|| Application.platform == RuntimePlatform.IPhonePlayer)
  22. return;
  23. if (Input.GetKey(KeyCode.W))
  24. {
  25. transform.Translate(Vector3.forward * Time.deltaTime * speed);
  26. }
  27. else if (Input.GetKey(KeyCode.S))
  28. {
  29. transform.Translate(Vector3.back * Time.deltaTime * speed);
  30. }
  31. if (Input.GetKey(KeyCode.A))
  32. {
  33. transform.Translate(Vector3.left * Time.deltaTime * speed);
  34. }
  35. else if (Input.GetKey(KeyCode.D))
  36. {
  37. transform.Translate(Vector3.right * Time.deltaTime * speed);
  38. }
  39. if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
  40. {
  41. transform.Rotate(Vector3.up, Input.GetAxis("Mouse X") * speed * 10);
  42. transform.Rotate(Vector3.left, Input.GetAxis("Mouse Y") * speed * 10);
  43. transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
  44. }
  45. if (Input.GetKey(KeyCode.Escape))
  46. {
  47. transform.position = positionReset;
  48. transform.eulerAngles = eulerAnglesReset;
  49. }
  50. #endif
  51. }
  52. }
  53. }