start dealing with corutines

This commit is contained in:
2023-03-14 06:09:21 +02:00
parent 6d26efe67c
commit 63daaaf3e5
3 changed files with 21 additions and 13 deletions
+8 -9
View File
@@ -1,5 +1,6 @@
using Assets.Scripts.Actions.Interfaces;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -63,7 +64,7 @@ public class Player : MonoBehaviour
{
if (IsBlockingAnimation(_currentAnimation))
{
if (IsAnimationStatePlaying(0, GetEnumMemberValue(_currentAnimation)))
StartCoroutine(IsAnimationStatePlaying(0));
return;
}
@@ -116,8 +117,6 @@ public class Player : MonoBehaviour
_navAgent.isStopped = false;
SetPlayerAnimation(AnimationStates.Walking);
//transform.position = Vector3.MoveTowards(_navAgent.transform.position, _navAgent.pathEndPosition, _navAgent.speed * Time.deltaTime);
// transform.position = _animator.(_navAgent.pathEndPosition);
_animator.SetFloat(WALK_VELOCITY, _navAgent.velocity.magnitude);
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
}
@@ -175,13 +174,13 @@ public class Player : MonoBehaviour
_currentAnimation = newState;
}
private bool IsAnimationStatePlaying(int animLayer, string stateName)
public IEnumerator IsAnimationStatePlaying(int animLayer)
{
if (_animator.GetCurrentAnimatorStateInfo(animLayer).IsName(stateName) &&
_animator.GetCurrentAnimatorStateInfo(animLayer).normalizedTime < 1.0f)
return true;
else
return false;
string stateName = GetEnumMemberValue(_currentAnimation);
var stateInfo = _animator.GetCurrentAnimatorStateInfo(animLayer);
yield return new WaitWhile(() => stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f);
yield break;
}
public void AddTask(PlayerTasks task)