ControlTransform.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ControlTransform : MonoBehaviour {
  5. [Range(0.1f,10f)]
  6. public float speed = 0.4f;
  7. Vector3 positionReset, eulerAnglesReset;
  8. void Awake() {
  9. positionReset = transform.position;
  10. eulerAnglesReset = transform.eulerAngles;
  11. }
  12. // Update is called once per frame
  13. void Update() {
  14. if(Application.platform == RuntimePlatform.Android)
  15. return;
  16. if(Input.GetKey(KeyCode.W)) {
  17. transform.Translate(Vector3.forward * Time.deltaTime * speed);
  18. } else if(Input.GetKey(KeyCode.S)) {
  19. transform.Translate(Vector3.back * Time.deltaTime * speed);
  20. }
  21. if(Input.GetKey(KeyCode.A)) {
  22. transform.Translate(Vector3.left * Time.deltaTime * speed);
  23. } else if(Input.GetKey(KeyCode.D)) {
  24. transform.Translate(Vector3.right * Time.deltaTime * speed);
  25. }
  26. if(Input.GetMouseButton(0) || Input.GetMouseButton(1)) {
  27. transform.Rotate(Vector3.up, Input.GetAxis("Mouse X") * speed * 10);
  28. transform.Rotate(Vector3.left, Input.GetAxis("Mouse Y") * speed * 10);
  29. transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
  30. }
  31. if(Input.GetKey(KeyCode.Escape)) {
  32. transform.position = positionReset;
  33. transform.eulerAngles = eulerAnglesReset;
  34. }
  35. }
  36. }