Skip to main content
Commonmark migration
Source Link

#You can't, it's private.

You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

public int GetScore() {
    return Score;
}

#You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

public int GetScore() {
    return Score;
}

You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

public int GetScore() {
    return Score;
}
added 61 characters in body
Source Link

#You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

public int GetScore() {
    return Score;
}

#You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

#You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().

public int GetScore() {
    return Score;
}
Source Link

#You can't, it's private.

Now, that's not the end of things, as I suspect that wasn't really your question.

Firstly, you need a reference to this script. Which you can get from a reference to the game object this script is attached to. GameObject.Find() works sometimes, I don't recommend it, but none the less, once you have the GameObject reference...

Game_Scene_Script sceneScript = gameObj.GetComponent<Game_Scene_Script>();
int score = sceneScript.GetScore();

Of course, that still means you need to either make the Score public or provide an accessor function, GetScore().