Advertisement
talmud

Cube Movement

Oct 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveCube : MonoBehaviour
  6. {
  7. public float speed;
  8.  
  9. // Update is called once per frame
  10. void Update()
  11. {
  12. Vector3 offset = Vector3.zero;
  13.  
  14. if (Input.GetKey(KeyCode.LeftShift))
  15. {
  16. if (Input.GetKey(KeyCode.UpArrow))
  17. {
  18. offset += Vector3.forward;
  19. }
  20. if (Input.GetKey(KeyCode.DownArrow))
  21. {
  22. offset -= Vector3.forward;
  23. }
  24. }
  25. else
  26. {
  27. if (Input.GetKey(KeyCode.UpArrow))
  28. {
  29. offset += Vector3.up;
  30. }
  31. if (Input.GetKey(KeyCode.DownArrow))
  32. {
  33. offset -= Vector3.up;
  34. }
  35. }
  36.  
  37. if (Input.GetKey(KeyCode.LeftArrow))
  38. {
  39. offset -= Vector3.right;
  40. }
  41.  
  42. if (Input.GetKey(KeyCode.RightArrow))
  43. {
  44. offset += Vector3.right;
  45. }
  46.  
  47. // apply offset
  48. transform.position += offset * Time.deltaTime * speed;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement