x


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.

more ▼

asked May 10 '10 at 11:49 AM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

assuming you have a RaycastHit variable from a raycast:

var destroy : DestroyObject = hit.transform.GetComponent(DestroyObject);
if (destroy != null) destroy.DestroyObject();
more ▼

answered May 10 '10 at 12:23 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5063
x1526
x477
x155
x108

asked: May 10 '10 at 11:49 AM

Seen: 1798 times

Last Updated: May 10 '10 at 11:49 AM