|
I have declared a static string in one script component of a gameobject, and am trying to access it in a script component of another game object. The static string is declared here: In the other script, I attempt to print the string to console and eventually use the string in some methods. The script as such gives the error: "Static member `PlayerStatus.mainStatus' cannot be accessed with an instance reference, qualify it with a type name instead" I've tried putting the script containing the static string into the Standard Assets folder to make sure it gets compiled first, so that's not a problem.
(comments are locked)
|
|
A static string does not exist on a class instance. In this case you have a PlayerStatus class instance on statusContainer. To access mainStatus.. you would do something like this.. currentStatus = PlayerStatus.mainStatus; But that won't work for your case, as it seems you want the value of mainStatus on a specific PlayerStatus gameObject instance. So simply change your declaration to I'd also suggest reading up on code formatting best practices. Public variables are usually in Capitals. So
(comments are locked)
|
