- Home /
How Would You call a function from parent via animation?
I want to know how you would call a function from a parent object via a script. A melee system object witch has the script that calls the animations on its child (the sword). i want the sword to call my function StopPlaying so that i will stop the swing after it has once. but i cant see the function in the animator. How would i do this?
Answer by MikeNewall · Jun 02, 2014 at 12:07 PM
You can access the parent object using transform.parent. Then get the Melee system component and call "StopPlaying". Stop playing must be public in order for it to be visible to other scripts.
transform.parent.GetComponent<MeleeSystem>().StopPlaying();
Or you could send a message to the parent like this:
transform.parent.SendMessage("StopAnimation");
When you send a message to a game object the named method is called on all of its components so if you have any other scripts attached with methods of the same name they'll get called too.
while this did help me when i was doing my old way where the animations where all in one script and object. I still cant get them to work from my swords animation to the melee systems function.
Your answer
Follow this Question
Related Questions
Cannot select function for Animation Event 0 Answers
AnimationEvent has no function name specified 2 Answers
Stop a function? 3 Answers
How to prevent a function from being called more than once 1 Answer
Weapon Shake 2 Answers