Home > database >  I'm getting "} Expected" Error even though I have matching braces
I'm getting "} Expected" Error even though I have matching braces

Time:01-02

when I was writing my code I got an error that I was missing a '}' on line 6. When I do put a } there, it tells me to put a { there instead. Since I'm new to Unity development, I might've just been stupid and not seen the problem, but here is the full error message if you need it: Assets\Scripts\Difficulty.cs(16,6): error CS1513: } expected. Here is the code too:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Difficulty : MonoBehaviour
{
    [SerializeField]
    public int difficulty;
    [SerializeField]
    float time;

    float timer = 0;  

    // Start is called before the first frame update
    void Start()
    {
        public bool updated = false;
        float timer = time;
    }

    // Update is called once per frame
    void Update()
    {
        if (time < 0)
        {
            updated = true;
            difficulty  ;
        }
    }
}

CodePudding user response:

You cannot declare local variables to be public

void Start()
{
    public bool updated = false;
    float timer = time;
}

move the public bool... line into the class scope, like int difficulty is

Not really sure what the line underneath is hoping to do, but avoid making local variables the same name as class scoped ones. You already have a float timer declared at class level, don't declare another at local method level

  •  Tags:  
  • c#
  • Related