Skip to content

Instantly share code, notes, and snippets.

@seferciogluecce
Created November 15, 2019 15:41
Show Gist options
  • Save seferciogluecce/b2c83468d159234057576ffdf9a44a44 to your computer and use it in GitHub Desktop.
Save seferciogluecce/b2c83468d159234057576ffdf9a44a44 to your computer and use it in GitHub Desktop.
if (Input.GetMouseButton(0)) //this changes for different approaches
{
mousePos = (Input.mousePosition);
Vector2 targetPos= new Vector2(Camera.main.ScreenToWorldPoint(mousePos).x, Camera.main.ScreenToWorldPoint(mousePos).y);
targetPos.x = Mathf.Clamp(targetPos.x, MinPos.x, MaxPos.x);
targetPos.y = Mathf.Clamp(targetPos.y, MinPos.y, MaxPos.y);
transform.position = targetPos; //this changes for different approaches
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment