- Home /
the variable has not be assigned
Really can't understand where is the error, I've this variable and a prefab assigned (It's a GUI texture)
var matchGUI : GameObject;
and this pice of code in a OnTrigger function:
var matchGUIobj = Instantiate(matchGUI, Vector3(0.15,0.1,0), transform.rotation);
It says that the variable matchGUI has not be assigned, but i've assigned it in the hierarchy, what's the problem?
Answer by StephanK · Nov 11, 2010 at 04:57 PM
This question is a bit confusing. What exactly did you assign to which Object?
If your script lives in a prefab maybe you assigned an object from your hierarchy as matchGUI? That won't work. You can only assign prefabs to prefabs in your assets.
my script is attached to my character, in the script there's the variable matchGUI, in the hierarchy i've give to this variable a prefab (a guitexture), then in the script i've tryed to instantiate it.
So if you look at your character in the inspector you can see that the variable has the prefab? and the prefab is not empty?
I have this exact same issue. This is from the unity Game development essentials ebook where you build a game. I got to this exact spot and get the same error!
Answer by fireant911 · Oct 22, 2013 at 06:10 PM
I just purchased Will's book and it is great; however, I, too, have come to a halt at this same point with the same error "The variable matchGUI of 'PlayerCollisions' has not been assigned". I have followed the procedures exactly and checked and rechecked everything yet the error still appears... but only after pressing Play' and grabbing the matches. Did anyone ever come up with a solution to this problem?,
Answer by MrSteve1 · Oct 25, 2013 at 05:05 PM
Hey Dudes, was suffering from this problem for quite some time, God knows why.... but when I created a prefab of an object that contained a variable that needed a assigning, it applied the same script "TWICE"
Select the object that has the script and scroll down the inspector, maybe you have two scripts!
Hope this helps!
Answer by allgood · Feb 18, 2014 at 08:55 PM
StephanK's answer above is correct. you have to select First Person Controller (which the PlayerCollisions script is attached to), drag MatchGUIprefab from Project panel and drop it over Match GUI variable of First Person Controller's Player Collisions (Script) component on Inspector.