private void Attack() { if (m_CurrentAttackCooldown > 0f) { m_CurrentAttackCooldown -= Time.deltaTime; AttackTarget = null; // we're not ready to attack, ignore the mouse hold or npc targeting from this frame } else if (AttackTargetIsInAttackRange()) { CharacterBehaviour characterBehaviour = AttackTarget.GetComponent <CharacterBehaviour>(); if (characterBehaviour != null && !characterBehaviour.Dead()) { m_CurrentAttackCooldown = AttackCooldown; m_Animator.ResetTrigger("Hit"); m_Animator.SetTrigger("Attack"); characterBehaviour.ApplyDamage(Damage); } AttackTarget = null; // we've executed the attack, require a new mouse hold/click or npc targeting } else if (InteractTargetIsInInteractRange()) { ItemPickup itemPickup = InteractTarget.GetComponent <ItemPickup>(); if (itemPickup != null) { GetComponent <CharacterInventory>().AddItem(itemPickup.ItemId); Destroy(InteractTarget); } InteractTarget = null; } }
public void EnemyAct() { Debug.Log(gameObject.name + "使用了技能1"); Debug.Log("名称:砍击"); m_Anim.SetTrigger("attack"); AttackTarget.GetComponent <RoleBase>().TakeDamage(attack); }
public virtual void AttackRangeCheck() { Vector2 dist = AttackTarget.transform.position - transform.position; // Get distance between NPC and target if (dist.magnitude <= AttackRange) // Is target within attack range? { attacked = true; Attack(AttackTarget.GetComponent <Character>()); // Attack target! } }
private bool InAttackRange() { if (!AttackTarget || !AttackTarget.Alive()) { return(false); } var targetCol = AttackTarget.GetComponent <CapsuleCollider>(); if (!targetCol) { Debug.LogWarning(name + "'s target does not have a capsule collider"); return(false); } var boxCol = GetComponent <CapsuleCollider>(); return((boxCol.transform.position - (targetCol.transform.position)).magnitude <= boxCol.radius * boxCol.transform.lossyScale.x + targetCol.radius * targetCol.transform.lossyScale.x + AttackRange); }
public bool AttackTargetIsAlive() { return((AttackTarget != null) && !AttackTarget.GetComponent <CharacterBehaviour>().Dead()); }