I am trying to save the scene using this script but I had 3 errors when I called the methods from different scripts I fixed two of them by making them static but don't know how to fix the 3 one at line 30.
script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerData : MonoBehaviour
{
void Awake()
{
DontDestroyOnLoad(gameObject);
}
public static void SaveScene()
{
int activeScene = SceneManager.GetActiveScene().buildIndex;
PlayerPrefs.SetInt("ActiveScene", activeScene);
}
public static void LoadScene()
{
int activeScene = PlayerPrefs.GetInt("ActiveScene");
//SceneManager.LoadScene(activeScene);
//Note: In most cases, to avoid pauses or performance hiccups while loading,
//you should use the asynchronous version of the LoadScene() command which is: LoadSceneAsync()
//Loads the Scene asynchronously in the background
StartCoroutine(LoadNewScene(activeScene));
}
IEnumerator LoadNewScene(int sceneBuildIndex)
{
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneBuildIndex);
asyncOperation.allowSceneActivation = false;
while (asyncOperation.progress < 0.9f)
{
yield return null;
}
asyncOperation.allowSceneActivation = true;
}
}
The script from which I am calling the methods:
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Saver : MonoBehaviour
{
private PlayerData playerData;
void Awake ()
{
playerData = GameObject.FindGameObjectWithTag("SceneHandler").GetComponent();
}
void Update()
{
PlayerData.SaveScene();
PlayerData.LoadScene();
}
}
↧