Hi, i would like to run OnPreCull function after certain button is pressed ? or maybe use it in custom function so i only run it when i run my custom function - is this even possible ?
Or is it maybe possible to define what camera should use OnPreCull ? i cant attach script to camera and have multiple cameras in scene…
OnPreCull fires only before frame get rendered. It is function like others so you can run it right after the button is pressed but if you need extra information about rendering or etc. that is avaible only before frame gets rendered i dont recomend you to do so. OnPreCull runs for all scripts in camera when this camera is ready to be rendered.
You can create your own camera component (meaning, you will attach the script to your camera game object). Simply keep a boolean variable in this class called say … usePreCull. Check this value at the top of your OnPreCull override, and return if false. Otherwise, let it proceed, and do what you want it to.
I’m not sure what button you mean, so in my example I used the “A” button of your keyboard:
public class MyCamComponent : MonoBehaviour
{
public bool usePreCull;
void Update()
{
usePreCull=Input.GetKey(KeyCode.A);//use precull while the "A" key is held down- only in play mode
}
void OnPreCull()//When a component on a camera, this function will be called
{
if (!usePreCull) return;
//do stuff
Debug.Log("Preculling now"); //warning, debug slow!
}
}