Forum Discussion
ebolt76
10 years agoHonored Guest
C# Raycast Hit open door and true false Bool questions
I have a scene that I am trying to click on collision boxes to interact with like opening a door and bouncing a ball for tests. I have this working, kind of. My questions are: With the GetButtonDow...
wheatgrinder
10 years agoExplorer
I've been wanting to replay, but Iv not tried your code yet.
Right off I would suggest turning your code upside down.
By that I mean. You should have your objects respond to the ray cast hit appropriately rather than have the code that is sending the ray cast do the work. Think of it as "Keeping my actions inside myself" to me it is easier to deal with. This is also way easier to debug. You can just write a script to test your actions THEN work on why your raycast isnt triggering the action.
Your ray cast code simply invokes some default procedure the colliders parent object when the reticle hits it. You can use layers or tags to set it so that your ray only triggers the default action on certain objects.
People say "sendmessage" is bad for this and there are better methods, but it woks for me. Using send message is very easy and you can even tell it to ignore the error that occurs if there is no "listener".. (send message options = DontRequireReceiver)
In my raycasters code I use something like:
On Button Down (A) hit.collider.sendmessage("Fire1")
Every object that I want to respond to ray cast and A button press has a "Fire1()" function. That function does the action..
hope this is helpful.
Right off I would suggest turning your code upside down.
By that I mean. You should have your objects respond to the ray cast hit appropriately rather than have the code that is sending the ray cast do the work. Think of it as "Keeping my actions inside myself" to me it is easier to deal with. This is also way easier to debug. You can just write a script to test your actions THEN work on why your raycast isnt triggering the action.
Your ray cast code simply invokes some default procedure the colliders parent object when the reticle hits it. You can use layers or tags to set it so that your ray only triggers the default action on certain objects.
People say "sendmessage" is bad for this and there are better methods, but it woks for me. Using send message is very easy and you can even tell it to ignore the error that occurs if there is no "listener".. (send message options = DontRequireReceiver)
In my raycasters code I use something like:
On Button Down (A) hit.collider.sendmessage("Fire1")
Every object that I want to respond to ray cast and A button press has a "Fire1()" function. That function does the action..
hope this is helpful.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 8 months ago
- 9 months ago