- Home /
Question by
Mattivc · May 10, 2010 at 11:49 AM ·
raycastprogrammingfunctionjavascript-specific
Calling function in a script based on raycast hit
How can i do the following I have duplicates of the same prefab in the scene. Each of these prefabs has a script with a function called DestroyObject, when called this function removes the object it is connected to.
How can a call the function in the script on the object that is hit by a raycast, and only have the one prefab that is hit by the raycast have its DestroyObject function called and subsequently be destroyed, while the rest of the duplicates of the same prefab are unafected.
Comment
Best Answer
Answer by Mike 3 · May 10, 2010 at 12:23 PM
assuming you have a RaycastHit variable from a raycast:
var destroy : DestroyObject = hit.transform.GetComponent(DestroyObject);
if (destroy != null) destroy.DestroyObject();