- Home /
How do I check if/where in a sprite another sprite is?
I have 2 sprites. A big sprite and a little sprite. I am dragging the little sprite on top of the big sprite. When I release the little sprite, I want to find out where on the big sprite the little sprite's center is, or to be notified if it was not dropped on the big sprite.
OnEnterCollision2D() does not work for me, because I am trying to perform this code from within another method. Is this possible/built-in with Unity?
I have this, but it seems very inconvenient for a game engine:
Bounds bigBounds= GetBigBounds();
if(transform.position.x > bigBounds.min.x && transform.position.x < bigBounds.max.x && transform.position.y > bigBounds.min.y && transform.position.y < bigBounds.max.y){
//It is inside of it
FindOutWhereItIsWithABunchOfMath();
}
I am looking for something along the lines of:
gameObject.GetRelativePosition(GameObject otherObject){
if(!otherObject.Contains(gameObject){
return relativePosition;
}
return null;
}
(but preferably something that works)
you can use oncollisionenter2d synchronizing with your function by using coroutine .Its like the update and oncollisionenter function work on seperate threads so passing values between these two will require synchronization between them.