Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour
  5. {
  6. public float movementSpeed;
  7. private Rigidbody rB;
  8.  
  9. // Use this for initialization
  10. void Start ()
  11. {
  12. rB = GetComponent<Rigidbody>();
  13. }
  14.  
  15. // Update is called once per frame
  16. void FixedUpdate ()
  17. {
  18.  
  19. if (Input.GetKey(KeyCode.LeftArrow))
  20. {
  21. rB.MovePosition(rB.position + Vector3.left * movementSpeed * Time.deltaTime);
  22. }
  23.  
  24. if (Input.GetKey(KeyCode.RightArrow))
  25. {
  26. rB.MovePosition(rB.position + Vector3.right * movementSpeed * Time.deltaTime);
  27. }
  28.  
  29. Vector3 pos = transform.position;
  30. pos.x = Mathf.Clamp(pos.x, -9.0f, 9.0f);
  31. transform.position = pos;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement