- Home /
Question by
troyle · Mar 07, 2014 at 02:16 PM ·
soundnullreferenceexceptionanimation events
Adding sound to animation: NullReferenceException
I'm trying to add sound queues to an animation clip and I seem to get this: NullReferenceException Sound.Update() (at Assets/Somping Sounds/Scripts/Sound.js:14)
#pragma strict
var audio1 : AudioClip;
var audio2 : AudioClip;
var audio3 : AudioClip;
function Update ()
{
if(Input.GetKeyDown("a"))
{
BassHit();
var BassEvent=new AnimationEvent();
BassEvent.functionName = "BassHit";
animation["WalkSync"].clip.AddEvent(BassEvent); // Add the event to an AnimationClip
}
if(Input.GetKeyDown("s"))
{
audio.PlayOneShot(audio2);
}
if(Input.GetKeyDown("d"))
{
audio.PlayOneShot(audio3);
}
}
function BassHit()
{
audio.PlayOneShot(audio1);
}
function SnareHit()
{
}
function HiHatHit()
{
}
Comment
Assu$$anonymous$$g that the lines match up , the problem's on
animation["WalkSync"].clip.AddEvent(BassEvent); // Add the event to an AnimationClip
so w/o knowing much, I'd just assume that there is no animation named "WalkSync"
since you seem to define BassEvent right before that line
There is defiantly the walk sync animation, it was created and attached to the same object as the script
Your answer
Follow this Question
Related Questions
NullReferenceException only at first run 2 Answers
How to best synchronize sound and animation event 0 Answers
Nullreference exception after creating asset 1 Answer
multiple Animation Events in an Animation 0 Answers
Animation and sound help 0 Answers