These are the objects that I want to set active between scenes:
When I start the game I want only Player1Score and Player1Name to be active. And on new scene load: SceneManager.LoadScene(SceneManager.GetActiveScene().name); I want these 2 to deactivate and Player2Score and Player2Name to set active. And like like that with the rest of the scores and names. But I have trouble with that. Even if I write: Player1Score.setactive(false) and Player2Score.setactive(true), on scene load I have once again only Player1score and name active. Does someone know how to fix that?
If all of this is on the same scene, you can use a PlayerPrefs integer called “TimesOpened” to store how many times the scene has been loaded by incrementing the value of “TimesOpened” in any start function then you can use the value of “TimesOpened” to decide what you should call SetActive() on eg if “TimesOpened” is equal to 1 then “Player1Score” and “Player1Name” Will have SetActive() called on them. Remember this only applies if everything that’s going to be SetActive() is on the same scene.
@ZY_bros Thank you for answering! I have one question. I made that code and it is not working. Can you tell me what is wrong with it?
public int TimesOpened = 0;
void Start()
{
TimesOpened++;
PlayerPrefs.SetInt("TimesOpened", TimesOpened);
if (PlayerPrefs.GetInt("TimesOpened") == 1)
{
Player1Score.SetActive(true);
Name1.SetActive(true);
}
if (PlayerPrefs.GetInt("TimesOpened") == 2)
{
Player1Score.SetActive(false);
Name1.SetActive(false);
Player2Score.SetActive(true);
Name2.SetActive(true);
}
if (PlayerPrefs.GetInt("TimesOpened") == 3)
{
Player2Score.SetActive(false);
Name2.SetActive(false);
Player3Score.SetActive(true);
Name3.SetActive(true);
}
if (PlayerPrefs.GetInt("TimesOpened") == 4)
{
Player3Score.SetActive(false);
Name3.SetActive(false);
Player4Score.SetActive(true);
Name4.SetActive(true);
}
}