Pickup object SetActive enemy AI

So, I’m trying to make a script where if the player picks up an object triggers a SetActive of my enemy. For starters, I set my enemy AI inactive. I need some help making the actual script that allows me to do everything I said above. I’m not the best programmer. Does anybody know how I can do this? If so, I’d really appreciate it if you could show me how. For instance, how do I get the enemy to switch from active to inactive upon the player picking up an object. Please and thanks in advance! :slight_smile:

Is it a particular enemy that you know beforehand or the closest enemy or something else? How do you do your object pickups?

Here’s something basic that could work:

public class Pickup : MonoBehaviour
{
  public string enemyName; // set this to the name of the enemy you want to enable / disable on pickup in the inspector

  private GameObject enemy;

  void Start()
  {
  // try to find the enemy to enable
  enemy = GameObject.Find(enemyName);

  // disable them by default
  if(enemy != null)
  enemy.SetActive(false);
  }

  void OnCollisionEnter()
  {
  // destroy this pickup object
  Destroy(gameObject);

  // turn on the enemy
  if(enemy != null)
  enemy.SetActive(true);
  }   
}