I have a toggle button that when pressed keeps its pressed on state until pressed again.
I’m trying to use this toggle button to set a device to be able to turn on a device when a countdown time finishes.

How can I do this?

I found what I had to do was to first create a bool for each toggle switch like this:

bool dev01State = false;
	bool dev02State = false;
	bool dev03State = false;

And then for my toggle buttons do this:

//Device One Toggle
	public void ToogleDeviceOne() {
		//Device Set to go off with timer Here
		dev01State = !dev01State;
	}

I repeat that last code for each toggle button.
And then the part that was driving me nuts at the end of my timer script I did this:

IEnumerator  Timing()
	{
		if (timer > 0) {
			//var minsDisplay : String = parseInt( timer / 60 ).ToString();
			minsDisplay = System.Convert.ToInt32( timer / 60 ).ToString();
			
			//var secsDisplay : String = parseInt( timer ).ToString();
			secsDisplay = System.Convert.ToInt32( timer ).ToString();
			
			if ( (timer - ( System.Convert.ToInt32(minsDisplay) * 60)) > 10 ) {
				secsDisplay = System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
			}
			else {
				secsDisplay = "0" + System.Convert.ToInt32( timer - ( System.Convert.ToInt32(minsDisplay) * 60) ).ToString();
			}
			
			//displayText.text = minsDisplay + " : " + secsDisplay;
		}
		//Timer Reaches End We Can Do Something Here
		else {
			timer += oldTimer;
			GetComponent<AudioSource>().PlayOneShot(Alarm);//Plays Alarm Sound
			isFinishedTimer = true;//Sets Inspector Value to true or false based on what is set here
			yield return new WaitForSeconds(5.8f);//Wait Time Setting
			//Do Something if Desired
			
			//if (GetComponent.<AudioSource>().isPlaying) return; // don't play a new sound while the last hasn't finished
			GetComponent<AudioSource>().clip = voices[Random.Range(0,voices.Length)];
			GetComponent<AudioSource>().Play();

			
			yield return new WaitForSeconds(0.8f);//Wait Time Setting
			//Do Something if Desired
			if (dev01State == true){
			Sending.sendRed2 ();
			}
			if (dev02State == true){
				Sending.sendRed ();
			}
			if (dev03State == true){
				Sending.sendGreen2 ();
			}
			//Sending.sendRed ();
			Debug.Log ("Timer Ended");
		}
		displayText.text = minsDisplay + " : " + secsDisplay;
	}

Drives me nuts it took me all day to figure that out so I’ll share it here just in case there is some other poor bugger like me trying to do the same thing :wink:

I don’t know if this helps but this is what I did

if ((Input.GetKeyDown(KeyCode.X)) == true)
{
if (world == false)
{
world = true;
}
else
{
world = false;
}

        }