- Home /
having trouble adding a button to end session
Hi everyone. I am trying to add a button that will appear after clearing a board in a game. The button is designed to end the level from continuing its process so users don't have to wait for a long time.
Below is some of the code that is calling the button to skip the level. The button name is called: SkipLevelBtn (skip level button).
The skip level button is hidden and then I used a simple show (boolean) to display the button when the target is reached during the game play.
IEnumerator BaseSession () { DebugPanel.Log("Status (Base)", "Session", "Began."); while (!limitationRoutineIsOver && !targetRoutineIsOver) { yield return 0; }
DebugPanel.Log("Status (Base)", "Session", "Waiting is over.");
// Checking the condition of losing
if (!reachedTheTarget) {
DebugPanel.Log("Status (Base)", "Session", "Session failed. Clearing.");
yield return StartCoroutine(GameCamera.main.HideFieldRoutine());
FieldAssistant.main.RemoveField();
ShowLosePopup();
DebugPanel.Log("Status (Base)", "Session", "Session failed. End.");
yield break;
}
iteraction = false;
DebugPanel.Log("Status (Base)", "Session", "Session completed. Waiting the cutscene.");
yield return new WaitForSeconds(0.2f);
UIAssistant.main.ShowPage("TargetIsReached");
AudioAssistant.Shot("TargetIsReached");
yield return StartCoroutine(Utils.WaitFor(() => CPanel.uiAnimation == 0, 0.4f));
// show skip button
UIAssistant.main.ShowPage("Field");
SkipLevelBtn.gameObject.SetActive (true);
DebugPanel.Log("Status (Base)", "Session", "Session completed. Bonus matching.");
// Conversion of the remaining moves into bombs and activating them
yield return StartCoroutine(BurnLastMovesToPowerups());
yield return StartCoroutine(Utils.WaitFor(CanIWait, 1f));
DebugPanel.Log("Status (Base)", "Session", "Session completed. Clearing.");
// Ending the session, showing win popup
yield return StartCoroutine(GameCamera.main.HideFieldRoutine());
FieldAssistant.main.RemoveField();
StartCoroutine (YouWin ());
//ShowCardPopup();
DebugPanel.Log("Status (Base)", "Session", "Session completed. End.");
}
Could anyone help with this simple issue. The button is not showing properly and the engine keeps saying that the button is not assigned even though it is.
Thanks
Answer by winterfluxstudio · May 16, 2018 at 12:12 AM
You should post the full code as it would make it easier to figure out what is going on.
Have you initialised a reference to the Button itself?
public GameObject SkipLevelBtn;
I'm not sure why you are calling SkipLevelBtn.gameObject.SetActive (true); it should be
SkipLevelBtn.SetActive (true);
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
$$anonymous$$eeps co$$anonymous$$g up with an error of SkipLevelBtn of SessionAssistant has not been assigned.
However, the game object is assigned to the script. Do you know a fix to this bug issue?
Answer by dinostudios123 · May 16, 2018 at 04:05 PM
Keeps coming up with an error of SkipLevelBtn of SessionAssistant has not been assigned.
However, the game object is assigned to the script. Do you know a fix to this bug issue?
Your answer
![](https://koobas.hobune.stream/wayback/20220612162740im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Main menu help needed (C#) 2 Answers
Cannot load scene: Invalid scene name (empty string) and invalid build index -1 3 Answers