title: how to activate enemies when there is a certain distance from player and enemy,and enemy is generated prefab?
body: <p>it works if i place enemy in starting zone but it doesn't if its generated with environment in 2d game.</p>
  <p>distance between enemy and player function</p>
  <pre><code>private float Distance()
      {
          return Vector3.Distance(Enemy.position, Player.position);
      }
  </code></pre>
  <p>if distance is less than 10 unit activate.</p>
  <pre><code>void FixedUpdate()
      {
          if (Distance() &lt; 10f)
          {
              if (!attack)
              {
                  // IF NOT ATTACKING TURN ON RUN ANIMATION ,WITH SET SPEED 
                  //print(&quot;Finding player&quot;);
                  animator.SetTrigger(movementAnimationString);
                  SetMovementSpeed(m_Speed);
                  animator.SetBool(&quot;IsAttacking&quot;, attack);
  
              }
              // enemy is next to player and should attack BY ACTIVATING ATTACK ANIMATION
              else
              {
                  SetMovementSpeed(0.0f);
                  animator.SetTrigger(attackAnimationString);
              }
          }
      }
  </code></pre>
  <p>As I said it only works on enemies manually placed in the hierarchy but not for those generated.</p>