Hi guys I made this basic script here, I’m following a tutorial. This script works but with different resolutions and such, it kinda breaks. If I used this script on a 1080p screen it wouldn’t let me move.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 7;
float screenHalfWidthInWorldUnits = 9.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float inputX = Input.GetAxisRaw (“Horizontal”);
float velocity = inputX * speed;
transform.Translate (Vector2.right * velocity * Time.deltaTime);
if (transform.position.x < -screenHalfWidthInWorldUnits) {
transform.position = new Vector2 (screenHalfWidthInWorldUnits, transform.position.y);
}
if (transform.position.x < screenHalfWidthInWorldUnits) {
transform.position = new Vector2 (-screenHalfWidthInWorldUnits, transform.position.y);
}
}