So I’m currently making a 2D platformer game with unity, and our character is able to shoot.
And we have 3 animations, 1 for preparing a shot, 1 for the actual shot, and then the preparation animation played backwards.
And I even managed to create mecanim states that work pretty good, the thing is now, my bullet spawns immediately. So how can i make my shoot script wait, until it is in the “Attack” State, at a certain keyframe, so i can assure, the shot is correctly synced up with the animation?
The problem is, i could use events and put the event at the fitting keyframe, but i want to use our shooting script also for enemies. So i can control it one time with our input system, and one time controlled by our AI script for enemies.
This is how our code in our shot method currently looks.
if (rangeAttackCooldown[0] >= rangeAttackCooldown[1])
{
if(anim!=null)
anim.SetTrigger("Shot");
GameObject proj = PPS.getProjectile();
if (proj != null)
{
currentProjectile = proj.GetComponent<Projectile>();
rangeAttackCooldown[0] = 0;
if (is_normal_shot)
currentProjectile.set_shooting_type(Projectile.Shooting_Type.NORMAL);
else
currentProjectile.set_shooting_type(Projectile.Shooting_Type.SPECIAL);
currentProjectile.shoot(2.0f, facingRight);
}
}