我有一个玩家对象和一个敌方物体,两边都有碰撞体,还有那里的武器,但是这会让他们在走进对方时造成伤害。我想要的是,如果“isAttacking”动画正在运行,他们只会造成伤害。我的代码连接到播放机和敌人的目的,是下面:Unity 5检查动画
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class detectHit : MonoBehaviour
{
public Slider healthbar;
Animator anim;
public string opponent;
public Collider ecollider;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag != opponent) return;
healthbar.value -= 20;
if (healthbar.value <= 0)
{
anim.SetBool("isDead", true);
ecollider.gameObject.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
}
}
我试过网上找,但大部分的东西是过时我觉得我需要做这样的事情:
if(anim.GetCurrentAnimatorStateInfo(0).IsName("isAttacking")){
healthbar.value -= 20;
}
但这不起作用,也许因为我没有看它看对手动画?如果是这样的话,我只是不知道如何寻找敌人的动画。
任何帮助将不胜感激。