// PRAGMA MARK - Static Public Interface public static BattlePlayer GetClosestEnemyPlayerFor(BattlePlayer player, Predicate <BattlePlayer> whereCondition = null) { BattlePlayer closestEnemyPlayer = BattlePlayer.ActivePlayers.Where(p => p != player) .Where(p => !BattlePlayerTeams.AreOnSameTeam(player, p)) .Where(p => whereCondition != null ? whereCondition.Invoke(p) : true) .MinBy(p => (p.transform.position - player.transform.position).magnitude); return(closestEnemyPlayer); }
private void OnTriggerEnter(Collider collider) { if (!HandleCollisions) { return; } Laser laser = collider.gameObject.GetComponentInParent <Laser>(); if (laser == null) { return; } if (lasersHit_.Contains(laser)) { return; } lasersHit_.Add(laser); CoroutineWrapper.DoAfterDelay(kClearLaserHitTime, () => { lasersHit_.Remove(laser); }); int damage = LaserDamage; // laser only does damage if not on same team // HACK (darren): BattlePlayer needs to be refactored in things like Laser / Teams // because BattlePlayer can be recycled it's not a good thing to keep track of // should instead make a HashCode-like thing if (laser.BattlePlayer != null && BattlePlayerTeams.AreOnSameTeam(laser.BattlePlayer, Player_)) { damage = 0; } GameNotifications.OnBattlePlayerLaserHit.Invoke(laser, Player_); Vector3 forward = laser.transform.forward; TakeDamage(damage, forward, damageSource: laser); laser.HandleHit(); }