I have an animation clip of a gun firing, the problem is the clip wasn’t made by me and I cant edit the clip in any way apart from tagging it in the animation window. Is it possible to access this tag by script so that I can trigger a projectile to instantiate when it plays?
Isn’t your code responsible for when the clip plays?
Methos is right, if it’s an AnimationClip and you’re playing it with the old animation system, then you can just start a coroutine or Invoke when you start the animation to fire a projectile X seconds after starting the clip.
Alternatively, you can go into the animation file and set an animation event- the event is basically a SendMessage delegate, so it’ll fire any function on every Component on the GameObject that’s playing the animation which matches the name and parameter type the event is given. In other words, if you make an event called FireProjectile, all functions called FireProjectile which accept the given parameter (or has no parameters) will fire on the animating object when that event is reached.
Finally, if using the mecanim animator system instead, then you can make a new StateMachineBehaviour and attach it to the animation node, then tell it to reach out to the animating object with animator.GetComponent().FireProjectile(); when that timing threshold has been crossed.
Not at the moment, when the enemy game object is enabled the animator starts right away and loops through a set of movement animation clips. All I need to do is trigger projectiles at certain times to sync with the right animation clips.
Thanks I will look at setting an animation event in the animation file, I just know my options are more limited as the animation wasnt created in Unity but i’ll see if I can figure it out.
Ah okay, it’s a long animation; now I get it.
In any event, you got some great options there in that other post. Good luck