Hi,
I have a few questions about using collider.raycast. I have a code snippet below that I’m using for a simple menu for touch devices. In the scene, I have one visible main menu button, and 3 hidden buttons for easy, normal and hard. The way it works, i press the main menu button, it disappears and the 3 other button appears.
The problem I have right now is that in the scene, if I position the main menu button on top of any of the other invisible buttons, pressing the menu button will also activate the collider of the ones below it. I’ve tried using the layer collision matrix but i think it only applies if I’m using physics.raycast. The only I fixed it is by positioning it so it doesn’t sit on top any of the other buttons(even if it’s hidden).
-
So my first question is there a way to ignore other game colliders when pressing a button using collider.raycast?
-
If using Physics.Raycast is the option to choose, it means I have to use tags to assign to each of the menu buttons right? I kept being told to avoid using tags since it will affect performance. Is that true?
Hope someone can help.
Thanks.
-
Hakimo
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetMouseButtonDown(0)) { if (startGame.collider.Raycast(ray,hit,100)) { // Main Menu Play button ButtonPressed(); yield WaitForSeconds(0.1); gameEasy.active = true; gameMedium.active = true; gameHard.active = true; startGame.active = false; } if(gameEasy.collider.Raycast(ray,hit,100)) { Application.LoadLevel(1); } if(gameMedium.collider.Raycast(ray,hit,100)) { Application.LoadLevel(2); } if(gameHard.collider.Raycast(ray,hit,100)) { Application.LoadLevel(3); } }
Glad to see you figured it out. Cheers
– hijinxbassist