public override void Interact(Interactable interactor) { isAttacking = true; interactorCombat = interactor.GetComponent <UnitCombat> (); if (interactorCombat == null) { Debug.Log(" NULL INTERACTOR "); return; } interactorCombat.Attack(myStats); base.Interact(interactor); }
public override void Interact(Interactable interactor) { isAttacking = true; enemyCombat = interactor.GetComponent <UnitCombat> (); if (enemyCombat == null) { Debug.Log(" NULL INTERACTOR "); return; } enemyCombat.Attack(targetStats: myStats); Debug.Log("Attacking Bldg"); base.Interact(interactor); }
void onMageAttack() { //here the mage finds it target that it wants to attack , 2 sets of code that are compared to eachther //beacuse there are two other team tags to consider EnemiesBlue = GameObject.FindGameObjectsWithTag(Enemie); foreach (GameObject enemie in EnemiesBlue) { UnitStats targetStats = enemie.GetComponent <UnitStats>(); if (blastradius >= Vector3.Distance(transform.position, enemie.transform.position)) { combat.Attack(targetStats); } } EnemiesRed = GameObject.FindGameObjectsWithTag("Red Team"); foreach (GameObject enemie in EnemiesRed) { UnitStats targetStats = enemie.GetComponent <UnitStats>(); if (blastradius >= Vector3.Distance(transform.position, enemie.transform.position)) { combat.Attack(targetStats); } } }
void Update() { //this code makes sure that this game object always targets the enemie closest to it //we do this by using the find closest enemy with tag function since there are 3 teams and 3 tags target = movement.FindClosestEnemy(Enemie, "Wizzard").transform; agent.SetDestination(target.position); Debug.DrawLine(gameObject.transform.position, target.transform.position, Color.grey); //drawing a line betwen the game object and its target to see in the debug scene float distance = Vector3.Distance(target.position, transform.position); if (distance <= agent.stoppingDistance) { //when the unit should start attaking is when the target is in range UnitStats targetStats = target.GetComponent <UnitStats>(); if (targetStats != null) { combat.Attack(targetStats); Debug.DrawLine(gameObject.transform.position, target.transform.position, Color.red); } } }
public void Attack(Unit target, bool rangedAttack = false) { unitCombat.Attack(target, rangedAttack); }