- Home /
I'm Getting Weird Bugs Today
I've written simple code like this a bunch of times, for some reason it chooses to stop working now. Why is this not working? It's saying SaveGame doesn't denote a valid type.
var posX : float;
var posY : float;
var sceneManager: GameObject;
function OnGUI(){
var status : SaveGame = sceneManager.GetComponent(SaveGame);
GUI.Label (Rect(posX, posY, 100, 20), "Cash: " + status.money);
}
The only thing I can replace "SaveGame" with is "Roll" which is super weird, can someone please tell me what's going on because I'm super confused.
Answer by hijinxbassist · Jun 01, 2012 at 05:00 AM
Is there a function called SaveGame in this script? That will cause the same error. Also you should not be getting that component in OnGUI or in Update(this means getting the component 1 or more times per frame). Throw that in Start() instead.
public var posX : float;
public var posY : float;
public var sceneManager: GameObject;
private var saveGame:SaveGame;
function Start()
{
saveGame=sceneManager.GetComponent(SaveGame);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'MouseLook' does not denote a valid type ('not found') -1 Answers
Perform Action on frame/time of animation 1 Answer
how to trigger another script in unityscript 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer