Converting JS to C# Problem

Hi guys im trying to convert my javascript to C# but there is have a problem with code;

using UnityEngine;
using System.Collections;

public class Pause : MonoBehaviour {
	 isPause= false;
	Rect MainMenu = new Rect(10, 10, 200, 200);
	
	void  Update (){
		if(CFInput.GetKeyDown(KeyCode.Escape))
		{
			isPause = !isPause;
			if(isPause)
				Time.timeScale = 0;
			else
				Time.timeScale = 1;
		}
	}
	
	void  OnGUI (){
		
		if(isPause)
			
			if(GUI.Button(new Rect(Screen.width/2.5f,Screen.height/6,Screen.width/5,Screen.height/7), "Main Menu"))
		{
			Application.LoadLevel("MainMenu");
			Time.timeScale = 1;
		}
		if(isPause)
			
			if(GUI.Button(new Rect(Screen.width/2.5f,Screen.height/2.5f,Screen.width/5,Screen.height/7), "Restart"))
		{
			Application.LoadLevel("Level1");
			Time.timeScale = 1;
		}
		if(isPause)
			if(GUI.Button(new Rect(Screen.width/2.5f,Screen.height/1.6f,Screen.width/5,Screen.height/7), "Exit Game"))
		{
			Application.Quit();
		}
		
		
	}
}

there is have problem with ‘isPause= false’ it’s says ;

“Unexpected symbol `=’ in class, struct, or interface member declaration”

i hope you guys can help thanks.

1 Answer

1

You need to add your type when defining a field in c#:

isPause= false;

should be:

bool isPause= false;

Thanks it worked :)

–