Search Unity

is it possible?

Discussion in 'Animation' started by bobbyrocks, Oct 31, 2016.

  1. bobbyrocks

    bobbyrocks

    Joined:
    Jan 27, 2014
    Posts:
    14
    Sorry first time posting here and I have searched the web and forums for a possible solution, maybe it cannot be done.

    Here is what I have.

    I have setup an attack animation for my main playable character.
    The Attack animation uses a state machine
    That I used 4 different types of attacks which were made into sub statemachines
    I put a script basically to randomly choose one of the 4 animations on attack..

    heres my problem...

    I would like to play a different sound on each of the substatemachines when it fires.
    Is that possible? or do I just need to stick with events and call a function on the animation?

    As you can tell i am still fairly new to this..

    Thanks for your help
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Do it with animation events, it the easiest way to play a sound at a specific time while an animation is playing
     
  3. bobbyrocks

    bobbyrocks

    Joined:
    Jan 27, 2014
    Posts:
    14
    actually not in this case because I am working on an MMO, so if i do it this way i would have several audio clips attached to my character and I just dont want to do that.. basically what i am trying to achieve here is when that animation plays.. it will play the attack animation - swing sound, then another animation can play and it will play a different type of sound. Sub state machines is perfect for this scenario.. Unity says it can be done.. but never gives an example on how to do it
     
  4. GrischaG

    GrischaG

    Joined:
    Apr 26, 2013
    Posts:
    40
    If you hit the trigger to play your animation just play a sound as well? You calculate the random value for the animation, so you know which one is playing and then you can play the specific sound.
    Does that help?
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes - in this case:
    Is correct.

    If you spent time to read you would see that events can just call a function of your choosing, and inside that function you can put whatever random code you want. Make sure you read the docs and understand as you are new. You don't need to put sound clips on specific characters at all.