I’m trying to use raycast to detect enemy object at front of my cannon, to see the raycast I drawLine. Look at the image above. back to your question. because the Bool FireON not working. I change the script now to make it more clear. but still the FireON bool not working !!
You gotta break it down into constituent steps, take it one step at a time:
spawn a sphere at the position you’re raycasting from - is it where you think it is?
spawn another sphere in the direction you think that ray is going… is that what you expect?
attach the debugger, put a breakpoint on line 7: does the raycast even hit at all?
with that breakpoint on line 7, inspect hit2.collider and see what its name is, tag, etc.
The easiest way to do the first two parts above is to put a Debug.Break() statement at the start of your FixedUpdate() call and then the editor will be frozen so you can go and find the two new spheres you created at those positions, then you can stop before you get 50,000 spheres everywhere.
Yes, you right. I solved. there is no error with the script except that the raycast line “6” start a little be away from it position. Now all things is good.