Show FPS when key press

Hi im using the FramesPerSecond.js script supplied here: -

where would i put a toggle command? (like press ‘z’ to turn it on and off)

Create a bool, that’s something like fpsEnabled.

Then, wrap everything in the Update function from that script with an:

//do all that stuff that's in the FPS Update function

Then we also:

//clear the text if fpsEnabled untrue 
//so we aren't left with the last FPS number sitting onscreen
guiText.text = "";

And add another if statement at the top of your Update(), it is your if(Input.GetKeyDown("whatever")). And inside that one, toggle the fpsEnabled bool by using fpsEnabled = !fpsEnabled;.

fpsEnabled = !fpsEnabled;

When you format your bool update like this, it works as a toggle each time it’s called. So if it’s true, it will become false, and if false it will become true. Simple and clean :slight_smile: