Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mecanim events

Discussion in 'Scripting' started by tawdry, Feb 1, 2015.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi
    Trying to have a sound play when foot lands but failing.
    So in import animations tab i choose events at bottom add function footstep and assign the sound "walk" in the object space . But when i run nothing happens seems have to write a script but don't know how could someone help had a look at the unity docs and do not understand them.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class mechy : MonoBehaviour {
    5.     Animator agent;
    6.     AudioSource aud;
    7.  
    8.     void start(){
    9.                 agent = GetComponent<Animator> ();
    10.         aud = GetComponent<AudioSource> ();
    11.     }
    12.  
    13.     void Onfootstep (){
    14.  
    15.     audio.Play(walk);
    16.    
    17.  
    18.         }}
     
    Last edited: Feb 2, 2015
  2. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    bumpity bump bump bump
     
  3. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Is Onfootstep() getting called ? ( you can do a Debug.Log to see that )
    If its getting called, then it has something to do with the audio.
     
  4. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hey Gamer yea it wasn't even calling it the docs said to use On in front but it calls it only when On is removed. So i can get it to work if i drag a sound clip into inspector but it only allows one soundclip so need to be able to call the sound by name so can't rely on this method.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class mechy : MonoBehaviour {
    5.     Animator agent;
    6.     public AudioClip walk;
    7.     void start(){
    8.                
    9.  
    10.     }
    11.  
    12.     void sound (){
    13.    
    14.         audio.PlayOneShot
    15.              (walk,5.3f);
    16.    
    17.  
    18.         }}
     
  5. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    What exactly is the purpose of that object box at the bottom of the event tab?
     
  6. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Hmm..Which box ?
    Can you post a screenshot of that ?
     
  7. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356

    Whats the purpose of this window other than setting the function name to be called the other fields seems to do nothing at all.Bah didnt load picture anyway when u press the button to set a event the event window opens with the function name a float a int and a object field.