- Home /
Accessing variables and arrays from inside classes?
If you have a class created at the start of the script, is there anyway to get variables or arrays from outside that class, say if you have a class function you want to create?
Something like:
var start : vector3 = (0,1,0);
class Player {
function Move (){
player.transform.position = start;
etc
}
}
Is it possible to do anything like this? Thanks for your time.
Answer by _Petroz · Nov 07, 2010 at 11:57 PM
It is possible using static variables. Static variables have global scope (can be accessed anywhere).
Great, thanks. That worked. Is there a way to do something like that for arrays as well? I couldn't find anything in the documentation about that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082250im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Declaring Variables in an Array of a Class 0 Answers
Editting a custom javascript class in the inspector 1 Answer
Different way to access class variables? 1 Answer
How to get the number of variables in a class, and then call the variable by its number. 1 Answer
Creating A Class Variable That Works With Any Class 0 Answers