- Home /
Question by
Crosby1 · Oct 31, 2018 at 02:55 PM ·
scripting problemsceneactivatescene loaddeactivate
Using OnSceneLoad (additive) to activate script on player within active scene
Hello!
There are three scripts on the player. One that activates movement when a certain scene loads. One that resets position and stops movement when the second scene loads, and the movement script. My current issue is getting the loading scene to properly activate/deactivate scripts with correct timing.
Here is my current nonworking script.
bool translate = false;
public GameObject Player;
void OnSceneLoaded(Scene scene04, LoadSceneMode Additive)
{
Debug.Log("Level04 is loaded");
translate = true;
}
void SceneUnloaded(Scene scene04 , LoadSceneMode Additive)
{
}
void Awake()
{
SceneManager.sceneLoaded += OnSceneLoaded;
Scene scene04 = SceneManager.GetSceneByBuildIndex(4);
Debug.Log("Movement Loaded");
}
{
void Update()
if (translate == false)
{
Player.GetComponent<SceneFall>().enabled = false;
}
if (translate == true)
{
Player.GetComponent<SceneFall>().enabled = true;
}
}
void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
There are a few issues I am aware of but I think I should be able to do what I need if I am able to do this simple task. I know that "SceneManager.sceneLoaded += OnSceneLoad" calls the fuction. My issue is getting this to be called when the certain scene is loaded.
This is probably trivial, but I would appreciate some help. Thanks ahead of time!
Comment