public void TrySetTarget(GameObject unitGo) { if (_targetEnemyIndex == null) { var unit = unitGo.GetComponent <Unit>(); if (unit.Stats.IsDead) { return; } _targetEnemyIndex = unit._unit.Index; _targetEnemyTeam = unit.Intell.IAm; } if (_targetEnemyIndex == null) { return; } //Debug.Log(gameObject.name + ": I will deal with the enemy (" + TargetEnemy.gameObject.name + ")"); var targetEnemy = Fight._.GetUnit(_targetEnemyTeam, _targetEnemyIndex.Value); var distance = Vector3.Distance(transform.position, targetEnemy.transform.position); if (_unit.Stats.AttackRange >= distance) { EnemyInRange(unitGo); } else { Intell.AtackSensor.gameObject.SetActive(true); _moveController.FollowObject(targetEnemy.transform); } }