Hello Unity Community
i’ve been working on a spot the difference game for the past 2 weeks and i’ve come across a problem i can’t seem to figure out. right now i’m checking to see if my mouse has clicked on a plane and if so then run the script. the problem i’m coming across is that i because my image has an alpha channel the plane matches the size of the whole image including the white background and it gives me a bigger plane than what i need. what i want to do is click on the plane and check if the alpha is zero ignore it.
i’ve recently come across RaycastHit and Physics.Raycast.
i used the example code i found in the unity documentation regarding raycast and with that realized that when i clicked on the plane it would draw white on every part of the plane. how can i use the data from my RaycastHit to see if i hit the actual texture i want and not the “white space” around the texture.
thanks for the help
The RaycastHit has a field for the uv coordinate of the point that was hit. If you know the uv coordinates that define the edges of the white border, you can check if the raycast hit inside the boundary.
sorry for the late response
thanks man i’ll try that out
hey andeeee
i used what you said although i’m doing it a little bit differently than what you describe but i’ve come across a new problem that i’m not sure how to handle. i’m using Physics.RaycastAll and the problem i’m having is that it’s not going through my items in the other that i have them place.
for example i have a foreground,midground, and a background. i loop through the raycast to see the order of the hits but on one of my objects it comes out midground,foredground, background and the other object it comes out midground,background,foreground. is there a simple method to organize the raycast in the proper other or should i somehow manually rearrange them?
I’m not looking at the docs right now (and I’m not sure if the docs specify one way or the other), but IIRC, the order in which the hits are returned is unspecified.
However, you should be able to sort them if need be, e.g. by using one of the .NET ‘sort’ functions and a custom comparator.
thanks a bunch jesse totally fixed my problem. i ended up creating my own sorting function but it works like a charm 