- Home /
Question by
Kattlelack · Jul 16, 2013 at 06:19 PM ·
animationbutton
Calling another script for an animation
I have a GUI button and when it is clicked I want it to activate an animation by calling another script. How do I do that?
Thanks for your help!
Comment
Best Answer
Answer by scarletshark · Jul 16, 2013 at 07:02 PM
To access other scripts, you need to find the GameObject that they are attached to, and the Component of that GameObject.
In C#:
Component OtherScript = GameObject.Find("gameobject").GetComponent<script>();
Please note, script name is not in quotes.
You can then do things like OtherScript.function();
In your OnGUI() function, add
if(GUI.Button(new Rect(50f,50f,100f,30f), "buttonText")){
OtherScript.function();
}
Please click the check mark next to my answer, because it is solved! No problem.
Could you please put it in JavaScript? Thank you a lot.