Advertisement
Kenkaster001

PLAYER

Sep 10th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Player : MonoBehaviour
  7. {
  8. public float movementSpeed = 10f;
  9. public float rotateSpeed = 200f;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13.  
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. Movement();
  20. }
  21.  
  22. private void Movement()
  23. {
  24. float x = 0, y = 0, z = 0;
  25.  
  26. if (Input.GetKey(KeyCode.W))
  27. {
  28. z = 1;
  29. }
  30.  
  31. else if (Input.GetKey(KeyCode.S))
  32. {
  33. z = -1;
  34. }
  35.  
  36. else if (Input.GetKey(KeyCode.A))
  37. {
  38. y = -1;
  39. }
  40.  
  41. else if (Input.GetKey(KeyCode.D))
  42. {
  43. y = 1;
  44. }
  45.  
  46. Vector3 vector = new Vector3(x, 0, z) * Time.deltaTime * movementSpeed;
  47. Vector3 rotation = new Vector3(0, y, 0) * Time.deltaTime * rotateSpeed;
  48. transform.Translate(vector);
  49. transform.Rotate(rotation);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement