#need help with raycast, how to make the object detect if it was hit by a raycast?

1 messages · Page 1 of 1 (latest)

lethal pollen
#

Where I only want it activate if the raycast is on the button

#

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?

eager vigil
eager vigil
simple cypress
#

Have a public bool canChange in Button which is turned true when it is casted upon

#

Also,

#

[]cb

fathom boughBOT
#

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.

lethal pollen
lethal pollen
eager vigil
eager vigil
#

output the hit and perform the operation on hit

#

with this variable do the operation

lethal pollen
#

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

eager vigil
#

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

lethal pollen
#

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