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);
}
}