Question about C# and using Methods...

Hi, I am currently trying to create a game that runs a basic thermostat

I have a basic function that that when a GUI button is clicked, it checks the if statement, if thats true, then decreases the ambient temperature by 1 every three seconds

Here is the code of the function…


int Choice;
	
	IEnumerator AC()
	{
	 int DesiredInt = 65;
	 int AmbientInt = 78;	
		
	 int Choice = 0;
		if (Choice == 0)
			{	
				if (AmbientInt > DesiredInt)
				{
				yield return new WaitForSeconds(3);
				AmbientInt -= 1;
				}
			}
	
	}

Here is the code I am trying to use to when I click the GUI button, it runs this function


if (GUI.Button(ACRectPercent,"A/C On"))
		{
	
			AC()
			{   // <--- LINE 75 HERE!
				
			}
						
		}

I keep getting an error for the top brace under “AC” that says

“Assets/Scripts/ACon.cs(75,25): error CS1525: Unexpected symbol `{'”


Ive never written anything in C# for Unity, so its been kind of a learning process.
Any help as to why I am getting this error would be greatly appreciated, or any pointer
on how to screw up less would also be appreciated

Please let me know if you need any extra info!

To call a co-routine, you have to use StartCoroutine(AC());

In short it should be ‘AC();’. If you give it braces, it thinks you are trying to define a method (or redefine in this case). Also, I don’t think you can yield within the OnGUI method but I’m not sure.