[ASK] ON/OFF BUTTON (Android)

I want to make on/off toggle flash button android, this my sample code :

using UnityEngine;
using System.Collections;

public class OON : MonoBehaviour 
{
	private bool mFlashEnabled = false;
	public Texture2D Icon;

	void OnGUI() 
	{
		if (GUI.Button(new Rect(5,5, 100, 100), Icon));
		{
			if (!mFlashEnabled)
			{
				CameraDevice.Instance.SetFlashTorchMode(true);
				mFlashEnabled = true;
			}
			else
			{
				CameraDevice.Instance.SetFlashTorchMode(false);
				mFlashEnabled = false;
			}
		}

	}
}

But it’s not working…
In play mode, if i click the button, still “Toggle flash OFF WORKED” (look the pic).
Anyone can help me?

From what i see... it seems to be working... You have 3 lines in your debug which shows it going from OFF, to ON, to OFF again. how is that not a toggle ? Unless that all happened in one click, i don't see the problem.

1 Answer

1

I think i just caught the error, You have a semicolon at the end of the Button line, remove it, I don’t believe it belongs there.

change this :

if (GUI.Button(new Rect(5,5, 100, 100), Icon));

to this :

if (GUI.Button(new Rect(5,5, 100, 100), Icon))

worked, thanks :)

mind accepting the answer ? :P