动作事件的应用

var otherClip01 : AudioClip;
var otherClip02 : AudioClip;

function Start()

   var sound01:AnimationEvent = new AnimationEvent();
  sound01.time = animation["attack_1"].clip.length*0.5f;
  sound01.functionName = "soundTemp01";//回调函数名
  animation["attack_1"].clip.AddEvent(sound01);
 
  var sound02:AnimationEvent = new AnimationEvent();
  sound02.time = animation["attack_2"].clip.length*0.5f;
  sound02.functionName = "soundTemp02";//回调函数名
  animation["attack_2"].clip.AddEvent(sound02);
}

function soundTemp01()
{
  audio.clip = otherClip01;
  audio.Play();
}

function soundTemp02()
{
  audio.clip = otherClip02;
  audio.Play();
}

你可能感兴趣的:(事件)