- Home /
How do I get a variable from another script and share the value of that variable between scripts?
I've been told to set variables to public, which I have - but I'm not sure if I've understood correctly that I have to have the scripts on the same game object? Is there no way to call out the variables from other scripts without having them on the same objects?
I have some variables I want to have in the player script to have a better overview. The variables are:
public var feetUp : boolean = false;
public var feetDown : boolean = true;
public var feetSouth : boolean = false;
public var feetNorth : boolean = false;
public var feetEast : boolean = false;
public var feetWest : boolean = false;
but I need to refer to them and change them in 6 other scripts with triggers. Can I call out the variables, and do I have to return a value for it to stay changed between the scripts? Not being a programmer and working with this for a while has made me a bit loopy, so I apologize in advance for any potential lack of sense.
ah... thanks! There's probably a few others I should also show this to.
Answer by Paulius-Liekis · Nov 05, 2012 at 01:01 PM
Read this tutorial: http://unitygems.com/mistakes1/