C# 协同程序动画未按预期播放
因此,就AI切换不同状态而言,一切似乎都在运行,但是当它进入玩家的范围时,状态在攻击中冻结,并且不播放任何攻击动画,我已经创建了带有骨骼操纵的AI,我想知道这是否会影响它,这是我调用动画的脚本,以及动画完成后返回idleFollow状态的脚本C# 协同程序动画未按预期播放,c#,unity3d,C#,Unity3d,因此,就AI切换不同状态而言,一切似乎都在运行,但是当它进入玩家的范围时,状态在攻击中冻结,并且不播放任何攻击动画,我已经创建了带有骨骼操纵的AI,我想知道这是否会影响它,这是我调用动画的脚本,以及动画完成后返回idleFollow状态的脚本 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeleeWeapon :
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeleeWeapon : Weapon
{
[SerializeField] private float attackDelay = 1f;
private Collider2D damageAreaCollider2D;
private Animator animatorAttack;
private bool attacking;
private readonly int useMeleeWeapon = Animator.StringToHash(name:"UseMeleeWeapon");
private void Start()
{
damageAreaCollider2D = GetComponent<BoxCollider2D>();
animatorAttack = GetComponent<Animator>();
//animatorAttack.Play(useMeleeWeapon);
}
public override void UseWeapon()
{
StartCoroutine(routine: Attack());
}
/*protected override void Update()
{
base.Update();
// FlipMeleeWeapon();
}*/
private IEnumerator Attack()
{
if (attacking)
{
yield break;
}
// Attack
attacking = true;
damageAreaCollider2D.enabled = true;
animatorAttack.Play(useMeleeWeapon);
// Stop Attack
yield return new WaitForSeconds(attackDelay);
damageAreaCollider2D.enabled = false;
attacking = false;
}
}
使用系统;
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共级近战武器:武器
{
[SerializeField]私有浮点攻击延迟=1f;
私人碰撞R2D损坏区域碰撞R2D;
私人动画师;
私人布尔攻击;
private readonly int-UseMeeBlue=Animator.StringToHash(名称:“UseMeeBlue”);
私有void Start()
{
损坏区域r2d=GetComponent();
animatorAttack=GetComponent();
//Animatoratck.Play(使用武器);
}
公共覆盖无效使用武器()
{
start例程(例程:攻击());
}
/*受保护的覆盖无效更新()
{
base.Update();
//flipmeleebarm();
}*/
私有IEnumerator攻击()
{
如果(攻击)
{
屈服断裂;
}
//攻击
攻击=正确;
DamageAreaCollizer2D.enabled=真;
Animatoratck.Play(使用武器);
//停止攻击
返回新的WaitForSeconds(attackDelay);
DamageAreaCollizer2D.enabled=错误;
攻击=错误;
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
[CreateAssetMenu(menuName=“AI/Decisions/Attack Completed”,fileName=“AttackCompleted”)]
公共类决策攻击已完成:辅助决策
{
公共覆盖布尔决定(状态控制器)
{
返回攻击完成(控制器);
}
私有布尔攻击已完成(StateController控制器)
{
if(controller.characterwearm.CurrentWearm.GetComponent().GetCurrentAnimatorStateInfo(0).length
>controller.characterwearm.CurrentWearm.GetComponent().GetCurrentAnimatorStateInfo(0.normalizedTime)
{
返回true;
}
返回false;
}
}
好的,我解决了这个问题,最后我把这个代码放到了武器近战脚本中,但是现在我遇到了一个奇怪的问题,AI在彼此靠近时总是试图面对左边而不是玩家。这与boxcollider2D有关,因此我在他体内放置了一个CapsualeCollider2D,并将脚本更改为CapsualeCollider2D。但这一问题仍在发生
private void OnTriggerEnter2D(Collider2D collision)
{
StartCoroutine(routine: Attack());
}
private void OnTriggerEnter2D(Collider2D collision)
{
StartCoroutine(routine: Attack());
}