Search Unity

How to use multiple param In Animation Event?

Discussion in 'Animation' started by TaesikYoon, Oct 27, 2015.

  1. TaesikYoon

    TaesikYoon

    Joined:
    Apr 28, 2015
    Posts:
    6
    I'm trying to use below code in Animation but it's not working.
    Can I use multiple parameter function in Animation?

    public void DoSomething(int myInt, string myString) {
    Debug.Log(myInt);
    Debug.Log(myString);
    }
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    No you cannot do that like this, but you can create a method that accept an animation event as parameter

    Code (CSharp):
    1.  
    2. public void DoSomething(AnimationEvent myEvent) {
    3. Debug.Log(myEvent.floatParameter);
    4. Debug.Log(myEvent.stringParameter);
    5. Debug.Log(myEvent.intParameter);
    6. }
     
    Flassi, funkyCoty, zeimhall and 6 others like this.
  3. TaesikYoon

    TaesikYoon

    Joined:
    Apr 28, 2015
    Posts:
    6
    Thanks! but I solved this problem with 'String.Split();'
     
  4. ozcomingfroo_unity

    ozcomingfroo_unity

    Joined:
    Oct 18, 2019
    Posts:
    1
    You have two options:

    1. Create a ScriptableObject with the parameters you want and add it to the function as a single parameter.
    2. As said by Mecanim-Dev, you can use AnimationEvent parameter, which gives you the option to add 1 of each primitive types (i.e. float, int string) and a "object" which is basically any "Asset object" which you have in your project.
     
    Flassi likes this.