ControlTransform.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 (Application.platform == RuntimePlatform.Android)
  21. return;
  22. if (Input.GetKey(KeyCode.W))
  23. {
  24. transform.Translate(Vector3.forward * Time.deltaTime * speed);
  25. }
  26. else if (Input.GetKey(KeyCode.S))
  27. {
  28. transform.Translate(Vector3.back * Time.deltaTime * speed);
  29. }
  30. if (Input.GetKey(KeyCode.A))
  31. {
  32. transform.Translate(Vector3.left * Time.deltaTime * speed);
  33. }
  34. else if (Input.GetKey(KeyCode.D))
  35. {
  36. transform.Translate(Vector3.right * Time.deltaTime * speed);
  37. }
  38. if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
  39. {
  40. transform.Rotate(Vector3.up, Input.GetAxis("Mouse X") * speed * 10);
  41. transform.Rotate(Vector3.left, Input.GetAxis("Mouse Y") * speed * 10);
  42. transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
  43. }
  44. if (Input.GetKey(KeyCode.Escape))
  45. {
  46. transform.position = positionReset;
  47. transform.eulerAngles = eulerAnglesReset;
  48. }
  49. }
  50. }
  51. }