- Home /
Set borders to mouse follower?
Hey, I'm using a mouse follower in my game. My problem is that, if the cursor moves too off it goes through objects. But i only want it to move in a pre-set field, Help please
EDIT: The Code
var depth = 10.0;
var speed = 1;
function Start ()
{
Screen.showCursor = false;
}
function Update ()
{
if(transform.position.y<1||transform.position.y>-1||transform.position.x<1||transform.position.x>-1)
{
var mousePos = Input.mousePosition;
var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth));
transform.position = wantedPos;
}
else
{
}
}
Comment
Your answer
Follow this Question
Related Questions
my gun wont follow my mouse 0 Answers
How to make an object orient to the mouse direction 0 Answers
Mouse cursor disappears in Web Player 0 Answers
Cant unlock cursor with FPS prefab 2 Answers
Cursor lock not working after alt tab 2 Answers