lets say i have a string variable “xyz” in script 1, and in script 2 i want to use that string.
I tried it by making that string a public string, like:
public string acc;
but how do i call for it in my second script?? because if just insert the acc as a variable, it throws an error
So let’s say I have a script called “GameMaster”
Here is the code in “GameMaster”
public class GameMaster : MonoBehaviour {
public string thing = "Hello World"
}
And then i have a script called “StringGet”
public class GameMaster : MonoBehaviour {
//This will be set to the game object the script is attached to
// Named "gm" for simplicity
GameObject gm;
//Name of script in our case "GameMaster"
// Named "gms" for simplicity
GameMaster gms;
void Start () {
// Name of game object that sccript is on
gm = GameObject.Find("GameMaster");
// Now actuallly finding the script
gms = gm.GetComponent<GameMaster>();
}
void Update () {
// Now we go "Gms." and then the name of the variable
debug.log(gms.thing);
}