- Home /
The question is answered, right answer was accepted
Acces variables before start()
Hey, I have 2 variables (floats) declared before the start() function, and now I want to create a vector3 variable (also before the start() function, but I can't access those floats. Should I create the Vector3 in the start() function? Or where should I declare all my variables within my script?
CODE:
public float OpenAngle = 90F;
public float CloseAngle = 0F;
Vector3 current = new Vector3(0, ..., 0);
Tyvm!!!
Why can't you access them ? Does it give you a compile error ?
Well it doesnt give an error, it actually works, guess it's just a wrong setting, because when I close the brackets of 'Vector3' first and then write x,y and z, it suggests me the Openangle value, consider it solved :)
Answer by Scribe · Jan 12, 2015 at 06:02 PM
you can create the Vector3 variable before start, but assign its value in start once the floats are properly accessible:
public float OpenAngle = 90F;
public float CloseAngle = 0F;
Vector3 current;
void Start(){
current = new Vector3(OpenAngle, 0, 0);
}
this way current is still a global variable (it can be used anywhere else within this class) but you can give it the correct values!