Search Unity

[HELP] How to trigger animations from another GameObject ?

Discussion in 'Animation' started by Micharneau, Dec 14, 2016.

  1. Micharneau

    Micharneau

    Joined:
    Dec 14, 2016
    Posts:
    11
    Hello,

    I'm currently creating a game (thank you Captain Obvious) and i have some problems : I want a gameObject (an empty one) to trigger another's GameObject's animation. How to do ? And is it possible to do so with every object in the scene ?
    N.B. : My script is in Java
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I'm gonna go easy on you since its your first day registered :p

    Ya gotta help us help you, a major thing would be to post some code to show us how you trigger your animations currently. Another thing is "Java" is not in unity, and its always referred to as javascript or unityscript (js for short) because its a special blend for unity.

    Anyway what your going after sounds like you need some kind of a "manager script" that is gonna handle the triggering of animations (perhaps on many things).... right? So What your gonna need to do is get a reference to the animator (assuming your using unity built in animation stuff) that runs your animation, and then change its state somehow to play the desired animation. There are many ways to go about doing that, such as a static class that keeps references to all the "animate-able" stuff, and when something happens to trigger an animation, you'd call the class in way like "AnimManager.Instance.AnimateTheThing()" from somewhere in code.
     
    theANMATOR2b likes this.
  3. Micharneau

    Micharneau

    Joined:
    Dec 14, 2016
    Posts:
    11
    o_O
    I'm sorry, but I don't really undersand the steps to follow in your message ("I'm French and new at Unity")
    I'm gonna try to re-explain my goal :
    - There are 2 GameObjects in my scene : A and B.
    - I want the GameObject A to trigger a function ("or a script") on the GameObject B to play an animation (or something else, nevermind).
    - The question is : How can I do this using JavaScript ? :confused:
    - And the little problem is I have absolutely NO idea of how to proceed, so I cannot give you a script (or i'm really dumb) :(

    Again, I'm really sorry for my difficulties. Also, thank you for taking your time for me ;)
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Well thats ok, I think it sounds like the first thing you should be doing is following lots of tutorials and learning as much about unity in general as you can. I'd start at unity3d.com/learn and then start searching for tutorials on the specific topics that interest you, and follow along doing each step as they show you how, so you can get the hang of things better.
     
  5. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
  6. Micharneau

    Micharneau

    Joined:
    Dec 14, 2016
    Posts:
    11
    Thanks, comrades ! xD
     
    MD_Reptile likes this.