@lament timber https://gyazo.com/d160a943786cd36333625c7342393c60/ I had this problem when re-adding this guy where he would shoot the arrow the very instant that he was doing moving, instead of waiting for the proper time in his animation
#Async stuff
1 messages · Page 1 of 1 (latest)
So I did this:
private Subject<bool> m_ShootAnimation = new();
private IObservable<bool> ShootAnimation() => m_ShootAnimation;
public void Shoot() //Called in animation events
{
m_ShootAnimation.OnNext(true);
}
protected override async UniTask ExecuteBehavior()
{
while (isActiveAndEnabled && Enemy.Targets[0] != null)
{
await GotoOverSeconds((Vector2)transform.position + FindStrafeDirection(strafeDistance, strafeRadius) * strafeDistance, 1 / (Enemy.Stats.GetStat(Stat.MoveSpeed) * strafeSpeed));
PlayAnimation(EnemyAnimationState.Stop);
await ShootAnimation().First(); //New thing to fix it
ShootProjectile(shootProjectile, transform.position, GetDirectionToFirstTarget());
await UniTask.Delay(TimeSpan.FromSeconds(2));
}
}
and it worked perfect first try!
But maybe there is an even simpler way to do it since I don't need to pass any values, I just need to notify it
Also: Is it fine to have behaviors with repeated logic have a generic, not enemy-specific name and re-use them? It will work properly that way but idk if it's bad practice or whatever.
that is what i do yes
cool thanks
you can use a unitaskcompletionsource instead of an iobservable for stuff like a complex animation that a bunch of things do. that way if it had already run for some reason, it will just work - meaning it will not wait for ANOTHER shoot animation
ah i see //Called in animation events
Ok, but now when it re-runs through the loop it instantly skips over awaiting the shoot animation
I need a way to like reset it, would I need to re-instantiate it?
Seems like re-instantiating it is working
hmm
okay i would do it the original way
sorry about that but it works