Hi. So i have a script that detects TAP and does something when i tap on an 2D object with a collider atached to it.My problem is that i have this on 3 separate objects and if i click any of them they all move(all have the same script and i cant put diferent scripts because i have 11 objects and i might have 2 of the same objects in the same scene on one of those 3).
Please help.Here is my code:
void Update()
{
if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer)
{
if(Input.touchCount > 0)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
checkTouch(Input.GetTouch(0).position);
}
}
}
}
void checkTouch(Vector3 pos)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(pos);
Vector2 touchPos = new Vector2(wp.x, wp.y);
var hit = Physics2D.OverlapPoint(touchPos);
if(hit.collider2D)
{
Move();
}
}