// Jimmy Vegas Unity Tutorials // This Script is for moving the player left and right along with the boundary using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMove : MonoBehaviour { public float moveSpeed = 3; public float leftRightSpeed = 4; void Update() { transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed, Space.World); if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { if (this.gameObject.transform.position.x > LevelBoundary.leftSide) { transform.Translate(Vector3.left * Time.deltaTime * leftRightSpeed); } } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { if (this.gameObject.transform.position.x < LevelBoundary.rightSide) { transform.Translate(Vector3.left * Time.deltaTime * leftRightSpeed * -1); } } } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class LevelBoundary : MonoBehaviour { public static float leftSide = -3.5f; public static float rightSide = 3.5f; public float internalLeft; public float internalRight; void Update() { internalLeft = leftSide; internalRight = rightSide; } }