OnTriggerStay Cpu lags

Hi guys, I’m making a litle game and I need to use OnTriggerStay to check the object arrounds, but this takes my cpu to 400ms and the framerate drops like hell… Is there a better way to do this?

public class Destroyer : MonoBehaviour {
   

    void OnTriggerStay(Collider other)
    {
        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        Spawner Spawn = GameObject.FindObjectOfType<Spawner>();
        if (Controller.Has_Placed2)
        {

            if (other.tag == "Banana" && this.tag == "Macaco" && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
            {
                EatIt(other);
            }
            if (other.tag == "Bambu" && this.tag == "Panda" && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
            {
                EatIt(other);
            }
            if (other.tag == "Osso" && this.tag == "Cao" && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
            {
                EatIt(other);
            }
            if (other.tag == "Cenoura" && this.tag == "Coelho" && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
            {
                EatIt(other);
            }
            if (other.tag == "Queijo" && this.tag == "Rato" && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
            {
                EatIt(other);
            }
        }

    }
    void OnDestroy() {

        Spawner Spawn = GameObject.FindObjectOfType<Spawner>();
        Spawn.Can_Spawn = true;
        Spawn.Can_Spawn_2 = true;

        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        Controller.Check_Fall = true;
        Debug.Log("DESTRUIU");
        Controller.IsEating = false;
    }

    void EatIt(Collider other)
    {
        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        Spawner Spawn = GameObject.FindObjectOfType<Spawner>();
        Spawn.Can_Spawn = false;
        Spawn.Can_Spawn_2 = false;
        Controller.IsEating = true;
        transform.position = new Vector3(other.transform.position.x, other.transform.position.y, other.transform.position.z);
        Destroy(other.gameObject);
        Destroy(gameObject, 1);
    }
}

OnTriggerStay is not recommended actualy , in my opinion . You should set a bool to true if OnTriggerEnter() is called and set it false when OnTriggerExit() is called . Then in a coroutine or in FixedUpdate , Update , LateUpdate , OnGUI , whatever make a statement like so :

bool isTrigger = false;
Collider colider = null;
void Update()
{
  if(isTrigger)
  {
     if(collider)
     {
        EatIt(collider);
     }
  }
}
void OnTriggerEnter(Collider col)
{
   isTrigger = true;
   collider = col;
}
void OnTriggerExit(Collider col)
{
    isTrigger = false;
    collider = null;

}
  1. method ‘FindObjectOfType’ si quite slow so I wouldn’t recommend to use it “frequently”
  2. use build-in ‘CompareTag’ method for comparing game-object tags

I made something similar to what you sayd, but now its not really doing the same thing.
It works when the object touches other objects, but not when others touches him…

   bool IsTrigger;
    Collider Col;
    void Start() {
        Col = null;
        IsTrigger = false;
    }

    void Update()
    {
        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        if (IsTrigger && Controller.Has_Placed == true && Controller.Has_Placed2 == true)
        {
            if (Col)
            {
                GoEat(Col);
            }
        }
    }


    void OnTriggerEnter(Collider other)
    {      
             if (other.tag == "Banana" && this.tag == "Macaco")
            {
                IsTrigger = true;
                Col = other;
            }
            else if (other.tag == "Bambu" && this.tag == "Panda")
            {
                IsTrigger = true;
                Col = other;
            }
            else if (other.tag == "Osso" && this.tag == "Cao")
            {
                IsTrigger = true;
                Col = other;
            }
            else if (other.tag == "Cenoura" && this.tag == "Coelho")
            {
                IsTrigger = true;
                Col = other;
            }
            else if (other.tag == "Queijo" && this.tag == "Rato")
            {
                IsTrigger = true;
                Col = other;
            }
    }
    
    void OnTriggerExit(Collider other)
    {
        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        if (other.tag == "Banana" && this.tag == "Macaco")
        {
            IsTrigger = false;
            Col = null;
        }
        else if (other.tag == "Bambu" && this.tag == "Panda")
        {
            IsTrigger = false;
            Col = null;
        }
        else if (other.tag == "Osso" && this.tag == "Cao")
        {
            IsTrigger = false;
            Col = null;
        }
        else if (other.tag == "Cenoura" && this.tag == "Coelho")
        {
            IsTrigger = false;
            Col = null;
        }
        else if (other.tag == "Queijo" && this.tag == "Rato")
        {
            IsTrigger = false;
            Col = null;
        }
    }

    void GoEat(Collider other) 
    {
        Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
        Spawner Spawn = GameObject.FindObjectOfType<Spawner>();
        Spawn.Can_Spawn = false;
        Spawn.Can_Spawn_2 = false;
        Controller.IsEating = true;
        transform.position = new Vector3(other.transform.position.x, other.transform.position.y, other.transform.position.z);
        Destroy(other.gameObject);
        Destroy(gameObject, 1f);
        
    }