Unity coding problem
Hey all I've been having a problem with unity. My Unity hasn't been liking the section of coding "loadingImage.SetActive(true);" saying "UnassignedReferenceException: The variable loadingImage of LoadOnClick has not been assigned." I am unsure as to what to do in this instance as i haven't had this problem before in Unity 5.1.0 the entire section of coding is at the bottom i wanted to ask if anyone could please help me with this thanks.
using UnityEngine; using System.Collections;
public class LoadOnClick : MonoBehaviour {
public GameObject loadingImage;
public void LoadScene(int level)
{
loadingImage.SetActive(true);
Application.LoadLevel(level);
}
}
Are you getting the error when you run the scene in the editor? Which would mean you haven't assigned anything to "loadingImage".
However, the error is also pointing to something called LoadOnClick, which I'm assu$$anonymous$$g is a function, but you haven't provided code for that. If you have a function called that, please provide that as the above code looks valid.
I'm currently actually following a Unity Tutorial and whats shown above is exactly what is supposed to be used and the only coding so far. I'm trying to develop a $$anonymous$$ain $$anonymous$$enu and in the tutorial the main menu is already working and i have followed it twice exactly and the coding is the only error that keeps occurring
Could you post a link to the tutorial then? And you don't have any other code anywhere?
Answer by BlackSnow_2 · Sep 01, 2015 at 03:52 AM
It just sounds like you haven't assigned the public variable as the image. The "Of LoadOnClick" is referring to the script's 'name' and it's simply returning a null when searching for the variable.
I may be wrong though, as I can't see your project, only the code and the error.
@Darkathion Click on the game object you've assigned the script to, find the script in the object's inspector and look for "loadingImage" with a box to the right of it... If the box says something like "loadingImage ($$anonymous$$ISSING)" or "Unassigned" you need to drag the Image object onto the box.
While fiddling around trying to get what you said to work i found the problem and it was exactly as you said and also another problem thanks a million for the help. Once i get my game to work completely if i ever publish it then ill put your name into the credits
Your answer
Follow this Question
Related Questions
Why is my "enemies " leaving the screen? 0 Answers
My components are disappears 1 Answer
esc key oddity 2 Answers
Unity Swipe menu 0 Answers