I am currently stuck on getting an error that is making it hard to figure out what is wrong. As you can tell I'm really new to this. Basically my code error says this
nullreferenceexcpetion: object refence not set to an instance of an object
NewBehaviourScript.start () (at location of file blah blah blah)
this is the code i wrote:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public GameObject soundControlButton;
public Sprite hie;
public Sprite nie;
// Start is called before the first frame update
void Start()
{
if (AudioListener.pause == true)
{
soundControlButton.GetComponent<Image>().sprite = hie;
}
else
{
soundControlButton.GetComponent<Image>().sprite = nie;
}
}
// Update is called once per frame
void Update()
{
}
public void SoundControl()
{
if (AudioListener.pause == true)
{
AudioListener.pause = false;
soundControlButton.GetComponent<Image>().sprite = nie;
}
else
{
AudioListener.pause = true;
soundControlButton.GetComponent<Image>().sprite = hie;
}
}
}
thank you so much for any help that can be given this is so important for me