- Home /
Error message "variable not assigned" ?
I do not receive this error message if the GameObject is Static but how do you assign a variable that is Not Static or is a moving GameObject? I'm trying to avoid using a 'Find" script.
here's what the message says.
"UnassignedReference Exception: The variable myGUIPlane of 'GUIPlaneOn' has not been assigned. You probably need to assign the myGUIPlane variable of the GUIPlaneOn script in the inspector.
So I dragged and dropped the 'GUIPlane' gameObject into the variable slot in the inspector(little icon appears) but then I get an error message. What am I doing wrong? I thought that by dragging and dropping the gameObject into the variable slot that it is "assigned" creating a reference to that object. But it's not working with moving objects that can't be Static in my game.. What am I doing wrong? Any suggestions? Thanx
Here's 2 scripts. The 'Find' script works with no error messages. The other does not.
this script works
function OnTriggerEnter( myzTrigger : Collider){
if(myzTrigger.gameObject.name == "tum1-1"){
var myGUIPlane : MeshRenderer =gameObject.Find("GUIPlane").GetComponent(MeshRenderer);
myGUIPlane.enabled = true;
}
}
This script gives me the error;
var myGUIPlane : MeshRenderer;
function OnTriggerEnter( myzTrigger : Collider){
if(myzTrigger.gameObject.name == "tum1-1"){
myGUIPlane.enabled = true;
}
}
I'd like to use the second script. Any suggestions? thanx
Answer by Lo0NuhtiK · Jan 10, 2012 at 05:10 AM
var myGUIPlane : GameObject ; //drag it on
function OnTriggerEnter(myzTrigger : Collider){
if(myzTrigger.gameObject.name == "tum1-1"){
myGUIplane.renderer.enabled = true ;
}
}
Your answer
Follow this Question
Related Questions
Change value of integer based on string input in a separate script 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to save a gameObjects on a prefab and variables with a script? 1 Answer
How to make reference from prefab to variable via C#/JavaScript? 1 Answer
Assigning varaibles to prefabs 1 Answer