Problem with a script

Hello every body I made this script for a game manager of a shooter game and I have a lot of errors when I compile it. Could anyone help me?

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

public class GameManager : MonoBehaviour
{
    public static Instance {get; private set;}

    public int gunAmmo = 10;

    private void Awake()
    {
        Instance = this;
    }
}

The errors are:

  • Assets\Scripts\Diferent\Game Manager.cs(7,28): error CS1519: Invalid token ‘{’ in class, record, struct, or interface member declaration

  • Assets\Scripts\Diferent\Game Manager.cs(7,32): error CS1519: Invalid token ‘;’ in class, record, struct, or interface member declaration

  • Assets\Scripts\Diferent\Game Manager.cs(7,45): error CS1519: Invalid token ‘;’ in class, record, struct, or interface member declaration

  • Assets\Scripts\Diferent\Game Manager.cs(11,5): error CS8803: Top-level statements must precede namespace and type declarations

  • Assets\Scripts\Diferent\Game Manager.cs(11,5): error CS0106: The modifier ‘private’ is not valid for this item

  • Assets\Scripts\Diferent\Game Manager.cs(15,1): error CS1022: Type or namespace definition, or end-of-file expected

Hello @Tecnosamba21 there is certainly a lot of errors here. =/
#1: I looks to me like you might be forgetting to add a type here. You declared it public, then you set it to a static and you assigned it’s name, BUT you forgot to specify what type it was. You probably want to set it to type GameManager.
Try this first, it might resolve several errors. Then let’s go from there. =)

2 Likes
public static GameManager Instance { get; private set; }

Update this line


public class GameManager : MonoBehaviour
{
    public static GameManager Instance { get; private set; }

    public int gunAmmo = 10;

    private void Awake()
    {
        Instance = this;
    }
}