- Home /
Problem is not reproducible or outdated
How can i trigger a script by collision with a box?
How can i trigger a script by collision with a box? I have a box collider on a object and a script on another object, how can i activate the script using the box Collider ?
You have to make the script named - say - Play, attach that to the other GameObject. Then create a function celebrate() inside the Play and invoke that.
Answer by Wolfram · Jun 26, 2012 at 11:38 PM
Hm? It is not clear to me what you are trying to do exactly. You want to access a script that is attached to the GameObject you assigned to "other"? Then you can use something like this:
other.GetComponent(PutTheNameOfYourScriptHere).ThisIsAFunctionInThatScript();
Note you declared "other" as being a GameObject, so other.Play("celebrate");
shouldn't work, since a GameObject does not have a function "Play" - it shouldn't even compile. If you're trying to start an animation named "celebrate", use other.animation.Play("celebrate");
instead.
what is this .ThisIsAFunctionInThatScript(); and what do i do?
It's an example. Do you have a script attached to "other"? What's it called? Which function do you want to call?
If the answer to any of this is "no" or "I don't know", please explain what exactly you are trying to do.
Yes the script is on other.Shoot1. i want to call an entire script on a different object.
You can not "call an entire script", only functions in that script. Please try to explain what you want to do in other (and more) words.
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# Scripts don't work in Unity 3.5 any idea why? 1 Answer
Unity Scripts Can be stolen?! 1 Answer
How do I not use a script? 2 Answers
How to get an NPC to wander around 3 Answers