Hey.
I know there are a lot of ways out there to access variables from other scripts.
A few that I know include:
static variables;
calling anotherScript;
but neither of these work for what I want to do. I have looked online in many places and haven’t found exactly what I’m looking for, and I’m sure I’m not the only one.
What needs to happen is all of these ways to access variables from other scripts should all be in one place, so if you know any good ways, leave them as an answer to this post with an example and explanation and we’ll try to make this post become gold for all newbie programmers.
Please leave the example in the following format so that it is easy to sift through all of the answers.
Example Format:
*Insert Explanation of what we need to do
*Insert code example on how to do it
*Variable names to be used are: ‘Script1’, the name of the script which contains the variable ‘string1’, and ‘Script2’, the name of the script which contains the variable ‘string2’.
Remember the goal of the answer should be to A. Show how ‘Script1’ can change it’s ‘string1’ to the value of the variable in ‘Script2’, ‘string1’. And/Or B. Show how ‘Script1’ can change the value of the variable ‘string2’ in ‘Script2’, to the value of ‘string1’ in ‘Script1’.
Make sure to do the answer in javascript. If you can also show code in C# than do both.
UpVote the best answers!