When I got to setting up the sword animation, I decided to set up a grenade throwing animation. I found a decent animation from Mixamo where the model started holding a rifle and then threw a grenade with their other hand, perfect for our model. I imported the animation as we have done other times and set up the transitions close to the sword ones. I was able to get everything set up, except that the grenade would fly and land all while the animation had just started. I wanted to set up an animation event, but I wasn’t sure how to write it up the way that we are using animations.
I was able to create an event, but since the animation is read only, I couldn’t wire a script to it. I ended up just putting the TakeAction into a coroutine with a delay in order to hack it. But I’m wondering if there’s away to do it using an animation event as I was trying. Most of my experience when using animations is actually pulling the animation out of the container it comes in with mixamo which then changes the animation from read only to read and write. However since we’re not using them this way I was wondering what alternatives there are.
Here’s my hack code:
public override void TakeAction(GridPosition gridPosition, Action onActionComplete)
{
OnThrown?.Invoke(this, EventArgs.Empty);
//hack to wait for animation to complete
StartCoroutine(Delay(gridPosition, onActionComplete));
}
IEnumerator Delay(GridPosition gridPosition, Action onActionComplete)
{
yield return new WaitForSeconds(2);
//Transform grenadeProjectileTransform = Instantiate(grenadeProjectilePrefab, _unit.GetWorldPosition(), Quaternion.identity);
Transform grenadeProjectileTransform = Instantiate(grenadeProjectilePrefab, grenadeThrowLocation.position, Quaternion.identity);
grenadeProjectileTransform.GetComponent<GrenadeProjectile>().Setup(gridPosition, OnGrenadeBehaviousComplete);
print("Grenade Action");
ActionStart(onActionComplete);
}
Thanks for your time!!!