how to stop dragging when object is at the corner of screen?,how to stop dragging 2d object when it is going out of screen?
void OnMouseDown ()
{
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
i am using this code...PleaseHelp :( void OnMouseDrag () {
Vector3 point = Camera.main.ScreenToWorldPoint (Input.mousePosition);
point.z = gameObject.transform.position.z;
point.y = gameObject.transform.position.y;
gameObject.transform.position = point;
}
,void OnMouseDown () { screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
using this code please help :( void OnMouseDrag () {
Vector3 point = Camera.main.ScreenToWorldPoint (Input.mousePosition);
point.z = gameObject.transform.position.z;
point.y = gameObject.transform.position.y;
gameObject.transform.position = point;
}
Answer by UnbreakableOne · Jun 11, 2018 at 05:51 PM
I'm not sure what your question is, but my best guess is that you don't want your objects get dragged out of the screen? You're calculating offset but does not seem to use it.
You maybe able to use Viewport to check if the object is outside bounds of the viewport. Check this out.
actually i simply want to drag tiles on screen and they should not overlap if 1 tile collide with other it should stop dragging
Your answer
Follow this Question
Related Questions
how can i anchor a point of a sprite to make it swing? 1 Answer
How do I keep my player colliders from thinking that the player is in the air. 0 Answers
How do i flip my character in 2D platformers,Im at a loss on flipping my 2D character 0 Answers
How can I make a 200×100 grid? 0 Answers
Tilemap doesn't showing on window?? unity 5.6.1f1 ,Tilemap not showing on the Window or as 2D Object 0 Answers