[Solved] Error CS1525: Unexpected symbol `else' - Help :D

:slight_smile:

using UnityEngine;
using System.Collections;

public class Pauser : MonoBehaviour
{
        private bool paused = false;
        private GameOverScriptP PauseMenu;

        void Start ()
        {
       
                PauseMenu = GetComponent<GameOverScriptP> ();
       
        }
   
        // Update is called once per frame
        void Update ()
        {
                if (Input.GetKeyUp (KeyCode.P)) {
                        paused = !paused;
                }

                if (paused)

                        Time.timeScale = 0;

                        PauseMenu.enabled = true;
   
                else

                        Time.timeScale = 1;

                        PauseMenu.enabled = false;


        }
}

Assets/UI Scripts/Pauser.cs(29,36): error CS1525: Unexpected symbol `else’

I am working on my most ambitious game ever lol and I cant even get the pause script to working haha :)must be a easy mistake I am missing. Can someone help? Thank you.

You must encapsulate the if/else blocks, if you only have one line of code inside an if-block you can skip the brackets ( or whatever they’re called in English. ) but since you have more lines in both your if and else block you will need to tell the compiler what should be performed.

if (paused) {
                       Time.timeScale = 0;
                        PauseMenu.enabled = true;
} 
             else {
                        Time.timeScale = 1;
                        PauseMenu.enabled = false;
}
1 Like
using UnityEngine;
using System.Collections;

public class PauseTest : MonoBehaviour {

    bool  paused = false;
    private GameOverScriptP PauseMenu;

    void Start ()
    {
      
        PauseMenu = GetComponent<GameOverScriptP> ();
      
    }
  
    void  Update (){

        if(Input.GetKeyUp (KeyCode.P)) {

            if(!paused){

                Time.timeScale = 0;
                paused=true;
                PauseMenu.enabled = true;

            }else{

                Time.timeScale = 1;
                paused=false;
                PauseMenu.enabled = false;
              
            }
        }

Thank you for the reply. I made it work like this.