OnLevelWasLoaded Problem was Found On
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
[HideInInspector]
public bool gameStartedFromMainMenu, gameRestartedAfterPlayerDied;
[HideInInspector]
public int Score, coinScore, lifeScore;
void Awake()
{
MakeSingleton();
}
void OnLevelWasLoaded()
{
Debug.Log("on Level Loaded");
if (SceneManager.GetActiveScene().name == "Gameplay")
{
if (gameRestartedAfterPlayerDied)
{
GamePlayController.instance.SetScore(Score);
GamePlayController.instance.SetCoinScore(coinScore);
GamePlayController.instance.SetLifeScore(lifeScore);
PlayerScoreScript.scoreCount = Score;
PlayerScoreScript.coinCount = coinScore;
PlayerScoreScript.lifeCount = lifeScore;
}
else if (gameStartedFromMainMenu)
{
PlayerScoreScript.scoreCount = 0;
PlayerScoreScript.coinCount = 0;
PlayerScoreScript.lifeCount = 2;
GamePlayController.instance.SetScore(0);
GamePlayController.instance.SetCoinScore(0);
GamePlayController.instance.SetLifeScore(2);
}
}
}
void InitializeVariables()
{
if (PlayerPrefs.HasKey("Game Initialized"))
{
GamePreferences.SetEasyDifficultyState(0);
GamePreferences.SetEasyDifficultyCoinScore(0);
GamePreferences.SetEasyDifficultyHighScore(0);
GamePreferences.SetMediumDifficultyState(0);
GamePreferences.SetMediumDifficultyCoinScore(0);
GamePreferences.SetMediumDifficultyHighScore(0);
GamePreferences.SetHardDifficultyState(0);
GamePreferences.SetHardDifficultyCoinScore(0);
GamePreferences.SetHardDifficultyHighScore(0);
GamePreferences.SetMusicState(0);
PlayerPrefs.SetInt("Game Initializes", 123);
}
}
void MakeSingleton()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}
public void CheckGameStatus(int Score, int CoinScore, int lifeScore)
{
if (lifeScore < 0)
{
if (GamePreferences.GetEasyDifficultyState() == 1)
{
int highScore = GamePreferences.GetEasyDifficultyHighScore();
int coinHighScore = GamePreferences.GetEasyDifficultyCoinScore();
if (highScore < Score)
GamePreferences.SetEasyDifficultyHighScore(Score);
if (coinHighScore < coinScore)
GamePreferences.SetEasyDifficultyCoinScore(CoinScore);
}
if (GamePreferences.GetMediumDifficultyState() == 1)
{
int highScore = GamePreferences.GetMediumDifficultyHighScore();
int coinHighScore = GamePreferences.GetMediumDifficultyCoinScore();
if (highScore < Score)
GamePreferences.SetMediumDifficultyHighScore(Score);
if (coinHighScore < coinScore)
GamePreferences.SetMediumDifficultyCoinScore(CoinScore);
}
if (GamePreferences.GetHardDifficultyState() == 1)
{
int highScore = GamePreferences.GetHardDifficultyHighScore();
int coinHighScore = GamePreferences.GetHardDifficultyCoinScore();
if (highScore < Score)
GamePreferences.SetHardDifficultyHighScore(Score);
if (coinHighScore < coinScore)
GamePreferences.SetHardDifficultyCoinScore(CoinScore);
}
gameStartedFromMainMenu = false;
GamePlayController.instance.GameOverShowPanel(Score, CoinScore);
}
else
{
this.Score = Score;
this.coinScore = CoinScore;
this.lifeScore = lifeScore;
gameStartedFromMainMenu = false;
gameRestartedAfterPlayerDied = true;
GamePlayController.instance.PlayerDiedRestartTheGame();
}
}
}
What is the problem? What is the error? Was this suppose to be a delegate to be used with Scene$$anonymous$$anager.sceneLoaded? Explain please.
OnLevelWasLoaded found on game manager warning comes on. and the level loading problem The void onlevelwasloaded is not reading
DontDestroyOnLoad is appearing after level reload
From Line 20-50 void (OnLevelWasLoaded) is not working
Answer by hexagonius · Oct 26, 2016 at 07:00 PM
Ah, ok... looking up a thread, it seems, that it's deprecated and taken over by the new SceneManager class.
https://community.unity.com/t5/5-4-Beta/OnLevelWasLoaded-deprecation/td-p/2557694
There is a sceneLoaded callback described in the docs:
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html
The docs are a bit sh*** about that right now, but this is how it works:
void Awake () {
SceneManager.sceneLoaded += LoadScene;
}
void LoadScene(Scene scene, LoadSceneMode mode){
Debug.Log ("Scene is loaded");
}
Answer by Raviraja190 · Oct 30, 2016 at 05:35 PM
I want Rectangle 2d to rotate when in air to the gravity and to be stopped at same position when colliding with the Object or any sprite.