Interaction with child objects

Is there a way you can trigger a script on a child object,

when you click the child object?

…I have tried to attach a script to a child object,
then run my project and clicking it, doesn’t work.

1 Answer

1

Easy. Two ways you could do this, possibly more but two simple ways.

First, you could use a Raycast. That will be able to determine which object you are clicking, and do something to it (like trigger a script)

Second, you could use the function OnMouseDown, but you would have to attach the script to the clickable object, and it would only work for that one object.

Note: The JavaScript and C# versions of the scripts will be written below in the comment section.