So, I’m making this game that has a Level Select screen with few levels and then each of those levels has a scene. This is the LevelSelect scene:
[175049-levelselect.png*_|175049]
And this is the script attached to the LevelManager in this scene:
private void Start()
{
PlayerPrefs.SetInt("Scene1stars", 3);
for (int i = 0; i < levelLoaders.Length; i++)
{
if(i == 0)
{
if(PlayerPrefs.GetInt("Scene1stars") == 0)
{
levelLoaders*.interactable = false;*
}
for (int j = 0; j < starsOne.Length; j++)
{
if (PlayerPrefs.GetInt(“Scene2stars”) > j)
{
starsOne[j].gameObject.SetActive(true);
}
}
}
if (i == 1)
{
if (PlayerPrefs.GetInt(“Scene2stars”) == 0)
{
levelLoaders*.interactable = false;*
}
for (int j = 0; j < starsTwo.Length; j++)
{
if (PlayerPrefs.GetInt(“Scene3stars”) > j)
{
starsTwo[j].gameObject.SetActive(true);
}
}
}
if (i == 2)
{
if (PlayerPrefs.GetInt(“Scene3stars”) == 0)
{
levelLoaders*.interactable = false;*
for (int j = 0; j < starsThree.Length; j++)
{
if (PlayerPrefs.GetInt(“Scene4stars”) > j)
{
starsThree[j].gameObject.SetActive(true);
}
}
}
}
if (i == 3)
{
if (PlayerPrefs.GetInt(“Scene4stars”) == 0)
{
levelLoaders*.interactable = false;*
}
}
}
}
This is a scene of the level1 for example (three stars on level 1 are just example of what happens if all three points in level 1 are collected):
[175050-levelscene.png|175050]
It has this script attached to the “points”:
public class PickUpPoints : MonoBehaviour
{*
public string levelName;_
private void Start()
{
levelName = SceneManager.GetActiveScene().name;
}
private void OnTriggerEnter(Collider other)
{
PlayerPrefs.SetInt(“Scene” + (SceneManager.GetActiveScene().buildIndex + 1 )+ “stars”, PlayerPrefs.GetInt(“Scene” + (SceneManager.GetActiveScene().buildIndex + 1) + “stars”) + 1);
}
}
Now, the problem is, if I for example click on level1 in the Level Selection screen to start the level1 scene and then while playing collect two points I will get two stars in the Level Selection scene even if I quit the “play” in the editor or touch a game over colliders (up or bottom black lines). I would like to make those stars appear in the Level Selection scene only if the player touches the Level finish collider, otherwise, I would like those points and stars not to be saved in the playerprefs. How can I do that?
*
*