Button problem : changing scenes fail ?
Hi guys, I'm having issuess with a button. In my game, when I press "P", few buttons are showing them up. When I press the button "Leave Quest", I'ld like a specific scene to load, passing by a loading screen. (I've linked script to the button, everything is ok here) I'm using a GameManager, set as a prefab, that will set a variable named "MapCount" to 0. Then, in my loading screen script, after a coroutine of 2 seconds, I've a switch looking on what's the MapCount of the GameManager, then sending him to my scene (with case 0, then.). Everything is working, if I do it with OntriggerEnter+GameObjects and things, but it's not working by button, and I'm pretty locked here. Any ideas ?
Edit this question with code from the Button and your Game$$anonymous$$anager, as well as instances of code where this functionality is working, and I can better assist you.
public class Pause$$anonymous$$enu : $$anonymous$$onoBehaviour {
public Game$$anonymous$$anagerLS game$$anonymous$$anager;
public string leaveQuest;
public GameObject pause$$anonymous$$enuCanvas;
void Update ()
{
if (isPaused)
{
pause$$anonymous$$enuCanvas.SetActive(true);
Time.timeScale = 0f;
}
else
{
pause$$anonymous$$enuCanvas.SetActive(false);
Time.timeScale = 1f;
}
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P))
isPaused = true;
}
public void LeaveQuest()
{
if (true)
{
game$$anonymous$$anager.Forest_ = false;
game$$anonymous$$anager.From$$anonymous$$ap_ = 1;
game$$anonymous$$anager.$$anonymous$$apCount_ = 1;
}
Application.LoadLevel("LoadingScreen");
}
}
(I've linked button with LeaveQuest)
public class Game$$anonymous$$anagerLS : $$anonymous$$onoBehaviour
{
public int From$$anonymous$$ap_;
public int $$anonymous$$apCount_;
public bool Forest_;
}
(Here is the Game$$anonymous$$anager)
public class LoadingScreenScript : $$anonymous$$onoBehaviour
{
public Game$$anonymous$$anagerLS game$$anonymous$$anager;
void Start()
{
StartCoroutine("Countdown");
}
private IEnumerator Countdown()
{
yield return new WaitForSeconds(2);
switch (game$$anonymous$$anager.$$anonymous$$apCount_)
{
case 0:
Debug.Log("pleasework");
Application.LoadLevel("Village_$$anonymous$$alou");
break;
case 1:
Application.LoadLevel("Foret001");
break;
}
}
Looks like your logic is kind of messed up. You have "StartCoroutine" in the Start method of your LoadingScreenScript. This will call it as soon as the game loads up, which I assume isn't what you want. I don't see any button code here that would trigger the "LeaveQuest" method either.
Also
if (true)
{
game$$anonymous$$anager.Forest_ = false;
game$$anonymous$$anager.From$$anonymous$$ap_ = 1;
game$$anonymous$$anager.$$anonymous$$apCount_ = 1;
}
The if statement is completely unnecessary, you are always going to evaluate that block of code, just remove it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612072345im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Struggling with bounce pad in platformer game. 1 Answer
Best Way To Have An Enemy NPC Chat With Player 0 Answers
How do I load tiles at runtime? 0 Answers
Missing function in button on click 0 Answers
How to add a restart to my 2D game? 0 Answers