Okay so Im new to code and I made this script to change the speed and spawn rate when you click the button difficulty but this appears and nothings changes when I click the button:
NullReferenceException: Object reference not set to an instance of an object
Difficulty.Medium () (at Assets/Difficulty.cs:26)
The code I have in the script is this one
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Difficulty : MonoBehaviour
{
public PipeMoveScript movespeed;
public PipeSpawnScript spawner;
void Start() //In here I access the variables from different scripts
{
movespeed = GameObject.FindGameObjectWithTag(“MoveSpeed”).GetComponent();
spawner = GameObject.FindGameObjectWithTag(“Spawner”).GetComponent();
}
public void Easy() // for example In here I try to change these variables and then apply the script in the button when clicked but nothing changes
{
movespeed.moveSpeed = 5;
spawner.spawnRate = 3;
Debug.Log(“Easy Difficulty”);
}
public void Medium()
{
movespeed.moveSpeed = 7;
spawner.spawnRate = 2;
Debug.Log(“Medium Difficulty”);
}
public void Hard()
{
movespeed.moveSpeed = 10;
spawner.spawnRate = 1;
Debug.Log(“Hard Difficulty”);
}
}