- Home /
Raycast Not Casting Java Script
var FirstPlot: GameObject;
if ( Input.GetMouseButtonDown (0)){ var hit: RaycastHit; var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, hit)) { if(hit.collider.tag=="Respawn") { Destroy(FirstPlot); } } }
Whats wrong, no errors are given out and yet the Cube isn't being destroyed? Thanks
Answer by MochiTo · Oct 15, 2017 at 08:15 PM
I cannot find your problem in you code, but with rays I've been helped most of the time with this. With this simple debug method you can see visually where your ray is pointing and also if it works as you really expected it to work:
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
Another possibility I see, is that you don't have the right spawned object set up in you FirstPlot variable.
Your answer
Follow this Question
Related Questions
How To Detect MouseClick Using Raycast Java Script 0 Answers
Raycast script help? 1 Answer
Raycast Tag of Hit GameObject 1 Answer
Raycast to Terrain (Conditional Statements) 1 Answer
raycast to object, load wrong script!? 2 Answers