So I have a script that changes the scene between 2 scenes
every 50 points but the script doesn’t work as intended and it constantly changes between the 2 scenes non stop and I don’t know how to fix it.
The script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public int TScore = 50 ;
private void Awake()
{
PlayerPrefs.GetInt("Tscore");
}
public void Update()
{
Scene currentScene = SceneManager.GetActiveScene();
string sceneName = currentScene.name;
PlayerPrefs.SetInt("Tscore", TScore);
if (PlayerPrefs.GetInt("ScoreNow") == PlayerPrefs.GetInt("Tscore"))
{
if (sceneName == "first" )
{
SceneManager.LoadSceneAsync("second");
}
if (sceneName == "second")
{
SceneManager.LoadSceneAsync("first");
}
TScore += 50;
}
}
}
The two if Statement execute one after the another.