Every single one of my scripts suddenly stopped working and Random.Range is no longer recognized. What do I do?

I attempted to create a system whereby collecting an item increases the player’s fire rate using the following pairs of scripts:

using UnityEngine;
using System.Collections;

public class ShootSpeedConsumeByContact : MonoBehaviour
{
    public GameObject absorb;
    public float spdValue;

    private GameController playerController;

    void Start()
    {
        GameObject playerControllerObject = GameObject.FindWithTag("Player");
        if (playerControllerObject != null)
        {
            playerController = playerControllerObject.GetComponent<GameController>();
        }
        if (playerControllerObject == null)
            Debug.Log("Cannot find 'PlayerController' script");
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary")
        {
            return;
        }
        if (other.tag == "Player" || other.tag == "Shield")
        {
            Instantiate(absorb, transform.position, transform.rotation);
            playerController.AddShootSpd(spdValue);
            Destroy(gameObject);
        }
        if (other.tag == "Projectile")
        {
            Instantiate(absorb, transform.position, transform.rotation);
            Destroy(other.gameObject);
            Destroy(gameObject);
        }
    }
}

and
using UnityEngine;
using System.Collections;

[System.Serializable]
public class Boundary
{
    public float xMin, xMax, zMin, zMax;
}

public class PlayerController : MonoBehaviour
{
    public float spread;
    public float speed;
    public float tilt;
    public Boundary boundary;
    private Rigidbody rb;

    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
    private float nextFire;
    private AudioSource audioSource;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
    }

    void Update ()
    {
        if (Input.GetButton("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            Instantiate(shot, new Vector3 (shotSpawn.position.x-spread,shotSpawn.position.y,shotSpawn.position.z), shotSpawn.rotation);
            audioSource.Play();
            spread = spread * -1;
        }
        
    }

    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.velocity = movement * speed;

        rb.position = new Vector3
        (
            Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
            0.0f,
            Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
        );

        rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    }

    public void AddShootSpd(float newShootSpdValue)
    {
        fireRate += newShootSpdValue;
    }
}

It wasn’t working and I wanted to show my friend how the game worked, so I turned off the pickup item’s script and the game ran fine. I turned the object back on and tried to fix the code, and suddenly all my scripts ceased functioning. I tried restarting Unity and this did not work, I tried reverting the scripts to what you see above and the game still would not run. I checked an unrelated script, and suddenly all my instances of Random.Range are underlined in red:

using UnityEngine;
using System.Collections;
using System;

public class GameController : MonoBehaviour {

    public GameObject hazard1;
    public GameObject hazard2;
    public GameObject hazard3;
    public GameObject boostOxy;
    public GameObject boostShield;
    public GameObject player;
    public GameObject playerExplosion;
    public GameObject shield;
    public Vector3 spawnValue;
    public int spawnCount;
    public int spawnCountIncrement;
    public int howManyBoostOxy;
    public int howManyBoostShield;
    public int howManyHazard1;
    public int howManyHazard2;
    public int howManyHazard3;
    public int wavesPerLevel;
    public float oxyUseTime;
    public float spawnWaitMin;
    public float spawnWaitMax;
    public float startWait;
    public float waveWait;
    public GUIText scoreText;
    public GUIText restartText;
    public GUIText gameOverText;

    internal void AddShootSpd(float spdValue)
    {
        throw new NotImplementedException();
    }

    public GUIText oxyText;
    public GUIText oxyGoneText;
    public GUIText waveNum;

    private int spawnNumber;
    private GameObject spawnedThing;
    private float spawnWait;
    private bool gameOver;
    private bool restart;
    private int score;
    private int oxygen;
    private int wave;
    private Vector3 spawnPosition;
    private Quaternion spawnRotation;

    void Start()
    {
        score = 0;
        oxygen = 180;
        wave = 1;
        UpdateScore();
        UpdateOxy();
        waveNum.text = "Wave " + wave;
        StartCoroutine(SpawnWaves());
        StartCoroutine(UseOxy());
        gameOver = false;
        restart = false;
        restartText.text = "";
        gameOverText.text = "";
        oxyGoneText.text = "";
        shield.SetActive(false);
    }

    void Update()
    {
        if (restart)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                Application.LoadLevel (Application.loadedLevel);
            }
        }
    }

    IEnumerator SpawnWaves()
    {
        yield return new WaitForSeconds(startWait);
        while (true)
        {
            for (int i = 0; i < spawnCount; i++)
            {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValue.x, spawnValue.x), spawnValue.y, spawnValue.z);
                Quaternion spawnRotation = Quaternion.identity;
                if (wave <= wavesPerLevel)
                {
                    spawnNumber = Random.Range(1, howManyBoostOxy + howManyHazard1);
                    if (spawnNumber <= howManyBoostOxy)
                    {
                        spawnedThing = boostOxy;
                    }
                    if (spawnNumber > howManyBoostOxy)
                    {
                        spawnedThing = hazard1;
                    }
                    Instantiate(spawnedThing, spawnPosition, spawnRotation);
                    spawnWait = Random.Range(spawnWaitMin, spawnWaitMax);
                    yield return new WaitForSeconds(spawnWait);
                }
                if (wave > wavesPerLevel)
                {
                    spawnNumber = Random.Range(1, howManyBoostOxy + howManyBoostShield + howManyHazard1 + howManyHazard2);
                    if (spawnNumber <= howManyBoostOxy)
                    {
                        spawnedThing = boostOxy;
                    }
                    if (spawnNumber > howManyBoostOxy && spawnNumber <= howManyBoostOxy + howManyBoostShield)
                    {
                        spawnedThing = boostShield;
                    }
                    if (spawnNumber > howManyBoostOxy + howManyBoostShield && spawnNumber <= howManyBoostOxy + howManyBoostShield + howManyHazard1)
                    {
                        spawnedThing = hazard1;
                    }
                    if (spawnNumber > howManyBoostOxy + howManyBoostShield + howManyHazard1)
                    {
                        spawnedThing = hazard2;
                    }
                    Instantiate(spawnedThing, spawnPosition, spawnRotation);
                    spawnWait = Random.Range(spawnWaitMin, spawnWaitMax);
                    yield return new WaitForSeconds(spawnWait);
                }
            }
            wave++;
            spawnCount = spawnCount + spawnCountIncrement;
            if (wave > 1 && wave <= 10)
            {
                spawnWaitMin = spawnWaitMin - 0.1f;
                spawnWaitMax = spawnWaitMax - 0.2f;
            }
            if (wave > 12 && spawnWaitMax > 0.5)
            {
                howManyBoostOxy--;
                spawnWaitMax = spawnWaitMax - 0.01f;
            }
            if (wave > 12 && spawnWaitMax <= 0.5)
            {
                howManyBoostOxy--;
            }
            if (wave > 20 && oxyUseTime > 0.05)
            {
                oxyUseTime = oxyUseTime - 0.005f;
            }
            yield return new WaitForSeconds(waveWait);
            waveNum.text = "Wave " + wave;
            if (gameOver)
            {
                restartText.text = "Press 'R' to restart";
                restart = true;
                break;
            }
        }
    }
    IEnumerator UseOxy()
    {
        yield return new WaitForSeconds(startWait);
        while (true)
        {
            oxygen--;
            UpdateOxy();
            yield return new WaitForSeconds(oxyUseTime);
            if (gameOver)
            {
                break;
            }
        }
    }
    public void AddScore(int newScoreValue)
    {
        score += newScoreValue;
        UpdateScore();
    }
    public void AddOxy(int newOxyValue)
    {
        oxygen += newOxyValue;
        UpdateOxy();
    }
    public void ActivateShield()
    {
        shield.SetActive(true);
    }
    public void DeactivateShield()
    {
        shield.SetActive(false);
    }
    void UpdateOxy()
    {
        oxyText.text = "Oxygen: " + oxygen;
        if (oxygen <= 0)
        {
            Instantiate(playerExplosion, player.transform.position, player.transform.rotation);
            DestroyObject(player);
            GameOver();
        }
    }
    void UpdateScore()
    {
        scoreText.text = "Score: " + score;
    }
    public void GameOver()
    {
        gameOverText.text = "Game Over";
        gameOver = true;
        if (oxygen == 0)
        {
            oxyGoneText.text = "you ran out of air";
        }
        if (oxygen > 0)
        {
            oxyGoneText.text = "the fish got you";
        }
    }
}

Visual Studio suggests I convert them to either System.Random.Range or UnityEngine.Random.Range. What do I do? How do I get my scripts to compile again? Which Random Range is the right one?

In your GameController you included the using statement “using System;” This is not generally a default using in a unity script. There are competing method names that conflict and visual studio stated as much(though you didn’t post the error :frowning: )

You should use UnityEngine.Random.Range but you will either need to fully qualify it with the namespace UnityEngine or you will need to alias the using System statement. The former is probably what you’re looking for.

Example, your SpawnWaves method:

// ... snip

IEnumerator SpawnWaves()
     {
         yield return new WaitForSeconds(startWait);
         while (true)
         {
             for (int i = 0; i < spawnCount; i++)
             {
                 Vector3 spawnPosition = new Vector3(UnityEngine.Random.Range(-spawnValue.x, spawnValue.x), spawnValue.y, spawnValue.z); // <-- HERE
                 Quaternion spawnRotation = Quaternion.identity;
                 if (wave <= wavesPerLevel)
                 {
                     spawnNumber = UnityEngine.Random.Range(1, howManyBoostOxy + howManyHazard1); // <-- HERE
                     if (spawnNumber <= howManyBoostOxy)
                     {
                         spawnedThing = boostOxy;
                     }
                     if (spawnNumber > howManyBoostOxy)
                     {
                         spawnedThing = hazard1;
                     }
                     Instantiate(spawnedThing, spawnPosition, spawnRotation);
                     spawnWait = UnityEngine.Random.Range(spawnWaitMin, spawnWaitMax); // <-- HERE
                     yield return new WaitForSeconds(spawnWait);
                 }
                 if (wave > wavesPerLevel)
                 {
                     spawnNumber = UnityEngine.Random.Range(1, howManyBoostOxy + howManyBoostShield + howManyHazard1 + howManyHazard2); // <-- HERE
                     if (spawnNumber <= howManyBoostOxy)
                     {
                         spawnedThing = boostOxy;
                     }
                     if (spawnNumber > howManyBoostOxy && spawnNumber <= howManyBoostOxy + howManyBoostShield)
                     {
                         spawnedThing = boostShield;
                     }
                     if (spawnNumber > howManyBoostOxy + howManyBoostShield && spawnNumber <= howManyBoostOxy + howManyBoostShield + howManyHazard1)
                     {
                         spawnedThing = hazard1;
                     }
                     if (spawnNumber > howManyBoostOxy + howManyBoostShield + howManyHazard1)
                     {
                         spawnedThing = hazard2;
                     }
                     Instantiate(spawnedThing, spawnPosition, spawnRotation);
                     spawnWait = Random.Range(spawnWaitMin, spawnWaitMax);
                     yield return new WaitForSeconds(spawnWait);
                 }
             }
             wave++;
             spawnCount = spawnCount + spawnCountIncrement;
             if (wave > 1 && wave <= 10)
             {
                 spawnWaitMin = spawnWaitMin - 0.1f;
                 spawnWaitMax = spawnWaitMax - 0.2f;
             }
             if (wave > 12 && spawnWaitMax > 0.5)
             {
                 howManyBoostOxy--;
                 spawnWaitMax = spawnWaitMax - 0.01f;
             }
             if (wave > 12 && spawnWaitMax <= 0.5)
             {
                 howManyBoostOxy--;
             }
             if (wave > 20 && oxyUseTime > 0.05)
             {
                 oxyUseTime = oxyUseTime - 0.005f;
             }
             yield return new WaitForSeconds(waveWait);
             waveNum.text = "Wave " + wave;
             if (gameOver)
             {
                 restartText.text = "Press 'R' to restart";
                 restart = true;
                 break;
             }
         }
     }

// end snip...

namespaces in c# are used to isolate and group functionality, this is particularly important when same named Methods/Classes exist, the compiler doesn’t known which one to choose and thus gets confused. You just need to be explicit.