Error On Code

Hi all, my code is not working with the following 4 errors:

Error CS8025 Feature ‘local functions’ is not available in C# 4. Please use language version 7.0 or greater line 40
Error CS8025 Feature ‘local functions’ is not available in C# 4. Please use language version 7.0 or greater line 46
Error CS0106 The modifier ‘public’ is not valid for this item line 40 Active
Error CS0103 The name ‘UpdateScore’ does not exist in the current context line 21 Active
Any help is greatly appreciated!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
    public GameObject hazard;
    public Vector3 spawnValues;
    public int hazardCount;
    public float spawnWait;
    public float startWait;
    public float waveWait;
    public GUIText scoreText;
    public int score;
    void Start()
    {
        score = 0;
        UpdateScore();
        StartCoroutine(SpawnWaves());
    }
    IEnumerator SpawnWaves()
    {
        yield return new WaitForSeconds(startWait);
        while (true)
        {
            for (int i = 0; i < hazardCount; i++)
            {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnWait);
            }
            yield return new WaitForSeconds(waveWait);
        }
        public void AddScore(int newScoreValue)
        {
            score += newScoreValue;
            UpdateScore();
        }
        void UpdateScore()
        {
            scoreText.text = "Score : " + score;
        }
    }
}

My first observation is that you have functions within functions, here’s the corrected version…

using System.Collections;
using UnityEngine;

public class GameController : MonoBehaviour {
    public GameObject hazard;
    public Vector3 spawnValues;
    public int hazardCount;
    public float spawnWait;
    public float startWait;
    public float waveWait;
    public GUIText scoreText;
    public int score;

    // --
    void Start() {
        score = 0;
        UpdateScore();
        StartCoroutine(SpawnWaves());
    }
    // --
    IEnumerator SpawnWaves() {
        yield return new WaitForSeconds(startWait);
        while (true) {
            for (int i = 0; i < hazardCount; i++) {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnWait);
            }
            yield return new WaitForSeconds(waveWait);
        }
    }
    // --
    public void AddScore(int newScoreValue) {
        score += newScoreValue;
        UpdateScore();
    }
    // --
    void UpdateScore() {
        scoreText.text = "Score : " + score;
    }
}

Please note that ‘GUIText’ is obsolete, it was replaced by the UnityEngine.UI system.

Thanks for the help, it worked!
May i also know why cant we have a function inside another function?

Local Functions (functions within functions) were introduced with C# 7.0, you can find the official information here. C# 6.0 is available in Unity on an experimental basis, so I assume C# 7.x is on the roadmap.