private bool InteractWithCombat() { RaycastHit[] hits = Physics.RaycastAll(GetMouseRay()); foreach (RaycastHit hit in hits) { // original try. // if(hit.collider != null ){ // var player = GetComponent<Combat.Fighter>(); // player.Fight(); // } CombatTarget target = hit.transform.GetComponent <CombatTarget>(); if (!GetComponent <Fighter>().CanAttack(target)) { continue; } if (Input.GetMouseButtonDown(0)) { print("in here"); GetComponent <Fighter>().Attack(target); target.GetComponent <Health>().TakeDamage(5f); } return(true); } return(false); }
public bool CanAttack(CombatTarget combatTarget) { if (combatTarget == null) { return(false); } Health targetToTest = combatTarget.GetComponent <Health>(); return(targetToTest != null && !targetToTest.IsDead()); }
public void Attack(CombatTarget combatTarget) { GetComponent <ActionScheduler>().StartAction(this); target = combatTarget.GetComponent <Health>(); }