#need help with raycast, how to make the object detect if it was hit by a raycast?
1 messages · Page 1 of 1 (latest)
because with the line of code I have now, whenever I press E it does turn on or off the light, that part is good, but where it goes wrong is that I can do it looking everywhere and anywhere, but I only want it to happen when I am looking and pressing E on the button
Here is my raycast code:
I think I have the solution where the origin of the raycast is on the player but I don't know how to put the main camera as the origin on the parameters
Please help am beginner, need help with raycast
need help with raycast, how to make the object detect if it was hit by a raycast?
Do anything you wish to do with it. This gameobject points to the gameobject that was hit by the ray after this you can get any component or script attached to the light
https://docs.unity3d.com/ScriptReference/RaycastHit.html
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Here are some unity docs....
Ignore the grey part it is just intellicode suggestion. you have other methods too...
Have a public bool canChange in Button which is turned true when it is casted upon
Also,
[]cb
Use codeblocks to send code in a message!
To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks like so:
```cs
// your code here
```
To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.
so wait where to I put this? inside the Physics.Raycast()?
what does this mean?
that's a bot command ignore
yeah after doing the raycast
output the hit and perform the operation on hit
with this variable do the operation
I think you misinterpret, in the "Button" how will I make it so that
if(I am hit by a raycast)
{
I will display "press E to interact" in the deubg log
Then I will also check if the player pressed E and If the light is on or off,
if the light is on I will turn off the light
if the light is off I will turn on the light
}
```\
This is going on in the button script
I'm sorry if its confusing, I am trying my best to explain as a newbie to coding xD
yeah but then what is the use of button then? The when the hitinfo returns the gameobject as light then enable the ui text that contains press E to interact and then if check if E is pressed or not
I removed the "Press E to interact" in the raycast script already, and the button will be responsible for turning the light on and off