GUI issues

Hi! I’m working on a GUI for class, and I can’t get part of it to work the way I want with the game it’s for. Any help would be great!

So I am using a GUI.RepeatButton, so I can hold down the button to recharge the characters energy. That functions ok for now, but I have a particle effect attached to the character that renderer.enabled = true; will make it show up. The problem is that it wont stop rendering when i let go of the button. If you need more of the code to understand what i’m doing just let me know! Thanks a ton!

//ENERGY COIL BUTTON
	if (GUI.RepeatButton (Rect (Screen.width - 613,Screen.height - 84, 65, 63), GUIContent (icon, coilTip) , coilOne)) {
		if (playerEnergy==1)
		{
		coilEffect.renderer.enabled = false;
		}
		if (playerEnergy<1)
		{
		coilEffect.renderer.enabled = true;
		}
	}

I’m more of an artist then a coder, so it’s been an adventure getting this far! :wink:

try moving the part of the code :

		if (playerEnergy==1)
		{
		coilEffect.renderer.enabled = false;
		}

outside of the button statement, just inside the Upadate or OnGUI function, also try making it

		if (playerEnergy>1)
		{
		coilEffect.renderer.enabled = false;
		}

If the objective is to have the particle effect visible only when the button is held down, and then only if playerEnergy is < 1, something like this will probably work better:

//ENERGY COIL BUTTON
	coilEffect.renderer.enabled = false; // ensure particles are turned off
	if (GUI.RepeatButton (Rect (Screen.width - 613,Screen.height - 84, 65, 63), GUIContent (icon, coilTip) , coilOne)) {
		if (playerEnergy<1)
		{
			// button is down AND energy is not max'd out; enable particles
			coilEffect.renderer.enabled = true;
		}
	}