private GameObject GetClosestEnemy() { Collider[] enemies = Physics.OverlapSphere(transform.position, stateVariables.eatRadius, LayerMask.GetMask(Strings.Tags.ENEMY)); if (enemies != null) { Collider closestEnemy = null; float closestDistance = Mathf.Infinity; foreach (Collider enemy in enemies) { IEatable eatable = enemy.GetComponent <IEatable>(); if (!eatable.IsNull() && eatable.IsEatable()) { float distance = Vector3.Distance(enemy.ClosestPoint(transform.position), transform.position); if (closestDistance > distance) { closestDistance = distance; closestEnemy = enemy; } } } if (closestEnemy != null) { return(closestEnemy.gameObject); } } return(null); }
private bool CheckForEatableEnemy() { GameObject potentialEatableEnemy = GetClosestEnemy(); if (potentialEatableEnemy) { IEatable skinnable = potentialEatableEnemy.GetComponent <IEatable>(); if (!skinnable.IsNull() && skinnable.IsEatable()) { stateVariables.eatTargetEnemy = potentialEatableEnemy; stateVariables.eatTargetEnemy.GetComponent <EnemyBase>().TemporaryTerminalIndestructable(); return(true); } } return(false); }
private void SetEnemyCloseToEat(Collider other, bool state) { if (other.tag.Equals(Strings.Tags.ENEMY) && !isInDashTutorial && isSpeedUpFinished) { IEatable skinnable = other.GetComponent <IEatable>(); if (!skinnable.IsNull() && skinnable.IsEatable()) { EnemyBase enemyBase = other.GetComponent <EnemyBase>(); if (enemyBase) { enemyBase.CloserToEat(state); if (state) { StartEatTutorial(); } } } } }