- Home /
execution order of Destroy and Physisc.Raycast
Hey kind guys, my situation is as follows: The 'cube' is collider placed in the way of raycast. I am destroying cube, then shooting ray...and the print says that it hit the cube. Why Destroy is executed after Raycast?
var hit : RaycastHit;
var cube : GameObject;
function Update()
{
if (Input.GetKeyUp ("x"))
{
Destroy(cube);
if (Physics.Raycast (Vector3(0,0,0), Vector3(0,0,-1), hit, 2.0))
{
print("you hit:"+hit.collider.gameObject);
}
}
}
The execution disorder occurs only when i'm trying to do this in one frame. When i put it into seperate function and add for example 'WaitForSeconds', then Destroy is executed first, after it: raycast, and it hits nothing.
Answer by mstevenson · Nov 17, 2012 at 08:33 AM
Destroy is always delayed, but will still execute within the span of a single Update cycle. In your case, I'd suggest setting cube.collider.enabled = false
Your answer
Follow this Question
Related Questions
when is pysics.raycast used, if it is called in Update() 1 Answer
How to destroy in an amount of time 1 Answer
How to destroy a gameobject by GameObject.Find 1 Answer
How do I prevent Updates in scripts to be called once an object has been destroyed? 1 Answer
How to implement "PreUpdate" function 4 Answers