- Home /
Move Bounderies
So I have a 2d object that follows my mouse. And I have values for x and y that i can't go past (so that the object wont go outside the screen) and it works, the object stops but then I can't move it at all... How can get back to moving it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float Xincrement;
public float speed;
public float maxWidth;
public float minWidth;
public float maxHight;
public float minHight;
public int health = 3;
void Start () {
Cursor.visible = false;
}
void Update () {
if (transform.position.x < maxWidth && transform.position.x > minWidth && transform.position.y < maxHight && transform.position.y > minHight) {
transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 10f));
}
}
}
Comment