void Attack(ShAI_U enemy) { attacking = true; enemyToAttack = enemy.transform; gun.Shoot(enemyToAttack.position - transform.position); if (!inCover) { FindIdealCover(); } Vector3 direction = enemyToAttack.position - transform.position; direction.y = 0f; transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(direction), 0.5f); FightWithinCover(); }
void LookOut() { List <ShAI_U> friendly = new List <ShAI_U> (); List <ShAI_U> enemies = new List <ShAI_U> (); List <ShAI_U> neutrals = new List <ShAI_U> (); List <CoverObjects> covers = new List <CoverObjects> (); Collider[] cols = Physics.OverlapSphere(transform.position, 30, overlapMask); for (int i = 0; i < cols.Length; i++) { if (cols[i].gameObject.layer == 8) // 8 == Soldier; { ShAI_U ai = cols [i].GetComponent <ShAI_U> (); canNotSeeEnemy = Physics.Linecast(eyes.position, ai.eyes.position, viewMask); if (ai.factiton != factiton && ai.factiton != Faction.neutral && !canNotSeeEnemy) { enemies.Add(ai); } else if (ai.factiton == factiton) { friendly.Add(ai); } // YOU CAN ALSO GATHER INFORMATION ABOUT NEARBY NEURALS, BUT AS FOR NOW, I DON'T NEED IT. } else // if it's not a soldier, it's a cover { covers.Add(cols[i].GetComponent <CoverObjects>()); // add that cover to the list; } } nearbyEnemies = enemies; nearbyCovers = covers; nearbyFriends = friendly; if (nearbyEnemies.Count > 0) { FindIdealEnemyToAttack(nearbyEnemies); } else { attacking = false; } }