Saturday, October 3, 2015

unity - How to check if a specific instance of a prefab is pressed?


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!


Heirarchy/inspector


Heiratchy/inspec




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...