#SceneManager.LoadScene return issue?
1 messages · Page 1 of 1 (latest)
Here's the full code as promised, Thanks!
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class mainMenuManager : MonoBehaviour
{
//Variables
public Animator mainMenuAnimator;
public GameObject menuSceneStuff;
public Scene gameLevel;
public saveDetails saveDetails;
public saveDetails playerDetails;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void MoveToLevelMap(){
Debug.Log("clicked play button, will now move to level map");
mainMenuAnimator.SetBool("slideIn", false);
mainMenuAnimator.SetBool("slideOut", true);
}
public void MoveToMainMenu(){
Debug.Log("clicked play button, will now move to main menu");
mainMenuAnimator.SetBool("slideIn", true);
mainMenuAnimator.SetBool("slideOut", false);
}
public void attemptToLoadLevel(string sceneName){
gameLevel = SceneManager.LoadScene(sceneName, LoadSceneMode.Additive); //load the scene
menuSceneStuff.SetActive(false); //disable the menu stuff, but keep them active as using these to store info and save data and etc
playerDetails = GameObject.FindGameObjectWithTag("Player").GetComponent<saveDetails>();
}
public void attemptToUnloadLevel(){
saveDetails = playerDetails; //grab player details (coin count, health, etc)
UnloadSceneAsync(gameLevel); //pseudo, yeah
}
}
Unity's giving me the error Assets\Scripts\mainMenu\mainMenuManager.cs(42,21): error CS0029: Cannot implicitly convert type 'void' to 'UnityEngine.SceneManagement.Scene'so i'm not sure if it's me being stupid haha
SceneManager.LoadScene returns void. so it returns nothing.
If you want to get the Scene then you can use:
SceneManager.GetSceneByName
plenty more at: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html