How can I detect whenever two of my colliders got hit by the raycast at the same time?
Here is my current code:
for(int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.GetTouch(i);
Ray ray = camera.ScreenPointToRay(Input.touches*.position);*
-
Physics.Raycast(ray, out hit);* -
//If A is touched* -
if(hit.collider.tag == "A")* -
{* -
Debug.Log("A");* -
}* -
//If B is touched* -
if(hit.collider.tag == "B")* -
{* -
Debug.Log("B");* -
}* -
//If A and B is touched at the same time* -
if(hit.collider.tag == "A" && hit.collider.tag == "B")* -
{* -
Debug.Log("C");* -
}* -
}*
What I want here to happen is to haveDebug.Log("C");executed.
But instead the things being executed areDebug.Log("A");andDebug.Log("B");
I don’t want “A” and “B” executed, I only want “C”.
EDIT: “C” does not get executed. Only A and B.
Is there a simple way I can do this?
Thanks!!
you will still be debug.log a and b because if a gets hit it will debug log a and if b gets hit it will debug log b but if you know it already works just delete the debug.log a and b.By the way does your C work?
– Albert-han@Albert han The C doesn't work. Only A and B. I guess I'll just make it an 'else if' statement if I didn't want A and B, but C doesn't work either way. [29218-untitled.jpg|29218]
– Leroterrmaybe it actually not being touched at the same time.I would do a yield wait for seconds and check for the other touch and then debug log it.
– Albert-hanThat was my guess too. It's not really being touched at the same exact time. Is there a better and easier way of doing this to get the effect I wanted? Thanks :) I'm also still a huge stranger to 'yield'. Might also work if there was something to check if the collider is being hit, not just if it got hit. Like, it would return true if it was being touched, then would automatically return false if the touch ended. Though I'm not sure if this is possible at all.
– LeroterrIt is possible but do you still want it to do if the user holds the screen?
– Albert-han