1

I am making a 3d platformer and it has different levels. When my player dies, there is a retry level option. The only problem is that I set it to load a certain level:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class re_start : MonoBehaviour
{
    public void playg()
    {
        SceneManager.LoadSceneAsync(1);
    }
}

As you can see, I only load my level 1. Is there a way I can create a variable that can be changed and visible to all scenes so I can put the level Ids there?

EDIT: I have tried creating a player pref. The only problem is that it keeps returning 0 instead of the ID of the scene.

Script here:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class pref : MonoBehaviour
{

    public void Update()
    {
        PlayerPrefs.SetInt("get_scene", SceneManager.GetActiveScene().buildIndex);
        Debug.Log(PlayerPrefs.GetFloat("get_scene"));
    }
    

}

Does anyone know why this keeps returning 0? EDIT: I foundthe issue. I did GetFloat instead of GetInt.

goody
  • 45
  • 5

0 Answers0