Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour
- {
- public float movementSpeed;
- private Rigidbody rB;
- // Use this for initialization
- void Start ()
- {
- rB = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void FixedUpdate ()
- {
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- rB.MovePosition(rB.position + Vector3.left * movementSpeed * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.RightArrow))
- {
- rB.MovePosition(rB.position + Vector3.right * movementSpeed * Time.deltaTime);
- }
- Vector3 pos = transform.position;
- pos.x = Mathf.Clamp(pos.x, -9.0f, 9.0f);
- transform.position = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement