Ok sO i managed to get my player to not go outside the screen but when you go to the edge of the screen you go Up, but stay inside the screen, was wondering how I can keep my transform.position.y always at 0
So this Dose Not happen
error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable
(I already have the RidgedBody set to Y, but it is still happening.)
public Vector3 moveDirection;
public CharacterController PlayerControll;
public float moveSpeed = 10;
public float YZero = 0;
public float GravityScale;
public GameObject Spawnpoint;
// Use this for initialization
void Start () {
Spawnpoint = GameObject.FindGameObjectWithTag ("SpawnPlayer");
transform.position = Spawnpoint.transform.position;
}
// Update is called once per frame
void Update () {
transform.position.y = YZero;
moveDirection = new Vector3 (Input.GetAxis ("Horizontal") * moveSpeed, 0f, Input.GetAxis ("Vertical") * moveSpeed);
moveDirection.y = moveDirection.y + (Physics.gravity.y * GravityScale);
PlayerControll.Move (moveDirection * Time.deltaTime);
Vector3 pos = Camera.main.WorldToViewportPoint (transform.position);
pos.x = Mathf.Clamp01(pos.x);
pos.y = Mathf.Clamp01(pos.y);
transform.position = Camera.main.ViewportToWorldPoint(pos);
}
}