This one is hard to explain, so I'll show the code first -
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if (hit)
{
clicksNeeded -= 1;
GetComponentInChildren().text = "" + clicksNeeded;
Debug.Log(clicksNeeded);
print("was a hit");
}
}
}
I need to check if hit touches the specific game object that the script is linked to, as at the moment if any of the circles are clicked, clicksneeded -= 1 to all objects currently instantiated.
Thanks for the help!
No comments:
Post a Comment