- Home /
Error Accessing Other Script's Variables
#pragma strict
var aEnemy : Transform;
var playerCharacter : GameObject;
playerCharacter = GameObject.Find("First Person Controller");
var script;
script = playerCharacter.GetComponent(PlayerControl);
var notesReceive : float = 0;
notesReceive = script.notes;
function OnTriggerEnter(other : Collider){
if(other.gameObject.name == "First Person Controller"){
Instantiate(aEnemy,Vector3(-1469.535,84.34768,408.0298),Quaternion(0,0,0,0));
script.notes += 1;
Debug.Log(script.notes);
Destroy(gameObject);
Destroy(GameObject.Find("KeyboxB"));
}
}
In my game, once the player reaches an objective, the global score is supposed to go up. In a script attached to a different object, there is a static var, notes. However, it doesn't seem to be changeable by other objects. I know asking this simple question may make me look like an idiot, but I must learn. The error is: Assets/Scripts/CollectB.js(14,23): BCE0019: 'notes' is not a member of 'Object'. However, this is repeated 3 more times throughout the script wherever the word "notes" is used...
I have tried working on this for hours on end, with different errors each time. I finally decided just to ask the community. Thanks to anyone who helps :)
Answer by iwaldrop · Feb 10, 2013 at 06:25 AM
You're accessing an instance of PlayerControl when you call script.notes. You need to add your value to PlayerControl.notes.
Where would I add that?
EDIT: Never$$anonymous$$d, I fixed it. Thanks. I ended up taking out all the variable declaration stuff and just adding in the code:
PlayerControl.notes += 1;
Debug.Log(PlayerControl.notes);
Your answer
Follow this Question
Related Questions
How can I edit my static variable in the editor? 1 Answer
Get script variable from collider 3 Answers
Access variables,method from a Mono Behaviour without static use. -1 Answers
How to watch variables from another script efficiently? 1 Answer
Accessing variables in a structure in a class from another class with cSharp 3 Answers