walben
1
This is a 2d top down game if it matters. I keep it flat.
I have an unknown number of sprites named („Unit_“+i)
When I click with the mouse on any location there is a method that checks the position on the grid. That position then goes to a new method that offsets the true hit so that it is at the same location as a Sprite Unit should be if it was there. The problem is, is it there, and if so, which one?
I have the location, and always will have it. What I don‘t have is the name on the location nor the object.
Any ideas?
public void CheackHit(Vector3 TrueHit)
{
Vector3 _check_hit;
_check_hit = TrueHit - _offset;
//SearchForAnyObject.Transform.Position = _check_hit;
//if anything found, return name
//if nothing found, return nothing
}
The typical solution is to put colliders on your sprites and do a Physics2D.Raycast() or Physics2D.OverlapPoint() to see what is hit.