Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How to make a script work in scene1 only if a collider in scene2 is triggered

$
0
0
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: ![alt text][1] 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[i].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[i].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[i].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[i].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): ![alt text][2] 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? [1]: /storage/temp/175049-levelselect.png [2]: /storage/temp/175050-levelscene.png

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>