- Home /
Modal Panel Problem
I've been having problems with my Modal Panel. It should be just showing an ok button that, when clicked, should take the users to another scene. But instead of showing just one button, it shows 4 and instead of opening a new scene, it just does nothing! Here's my code:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System.Collections;
public class ModalPanel : MonoBehaviour {
public Text question;
public Button yesButton;
public Button noButton;
public Button cancelButton;
public Button okButton;
public GameObject modalPanelObject;
private static ModalPanel modalPanel;
public static ModalPanel Instance () {
if (!modalPanel) {
modalPanel = FindObjectOfType(typeof (ModalPanel)) as ModalPanel;
if (!modalPanel)
Debug.LogError ("There needs to be one active ModalPanel script on a GameObject in your scene.");
}
return modalPanel;
}
//Yes/No/Cancel/Ok: A string, A Yes event, a no event, an OK event and a cancel event
public void Choice (string question, UnityAction yesEvent, UnityAction noEvent, UnityAction cancelEvent, UnityAction okEvent) {
modalPanelObject.SetActive (true);
yesButton.onClick.RemoveAllListeners ();
yesButton.onClick.AddListener (yesEvent);
yesButton.onClick.AddListener (ClosePanel);
noButton.onClick.RemoveAllListeners ();
noButton.onClick.AddListener (noEvent);
noButton.onClick.AddListener (ClosePanel);
cancelButton.onClick.RemoveAllListeners ();
cancelButton.onClick.AddListener (cancelEvent);
cancelButton.onClick.AddListener (ClosePanel);
okButton.onClick.RemoveAllListeners ();
okButton.onClick.AddListener (okEvent);
Application.LoadLevel("MainScene");
okButton.onClick.AddListener (ClosePanel);
this.question.text = question;
yesButton.gameObject.SetActive (false);
noButton.gameObject.SetActive (false);
cancelButton.gameObject.SetActive (false);
okButton.gameObject.SetActive (true);
}
void ClosePanel() {
modalPanelObject.SetActive (false);
}
}
Please Help Me!
Please post the code that calls the Choice function.
Here:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System.Collections;
public class Test$$anonymous$$odalWindow : $$anonymous$$onoBehaviour {
private $$anonymous$$odalPanel modalPanel;
private UnityAction myYesAction;
private UnityAction myNoAction;
private UnityAction myCancelAction;
private UnityAction myOkAction;
void Awake () {
modalPanel = $$anonymous$$odalPanel.Instance ();
myYesAction = new UnityAction (TestYesFunction);
myNoAction = new UnityAction (TestNoFunction);
myCancelAction = new UnityAction (TestCancelFunction);
myOkAction = new UnityAction (TestOkFunction)
}
// Send to the $$anonymous$$odal Panel to set up the Buttons and Functions to call
public void TestYNC () {
modalPanel.Choice ("This scene is unavailable", TestOkFunction);
}
// These are wrapped into UnityActions
void TestOkFunction () {
Application.LoadLvel("$$anonymous$$ainScene");
}
Answer by FortisVenaliter · Jun 12, 2015 at 08:00 PM
Okay... so the function takes in a String and 4 unity events. When you call it, you only provide a String and 1 unity event. How does that even compile? You need to provide all the arguments for it to work.
But I only Want an O$$anonymous$$ button. Should I just delete private UnityAction myYesAction, private UnityAction myNoAction andprivate UnityAction myCancelAction. Also I havent saved it yet. Where am I meant to equip it. Should i equip it on _$$anonymous$$anager
You'll need to specify which buttons you want. You can do so by passing null for those events if you want, but then you need to check for that null and deactivate the buttons that are not necessary.
I'm starting to get the error:
error CS1501: No overload for method
Choice' takes
2' arguments
Yes, that's exactly what I was describing. You need to provide the number of arguments it's asking for.
Also, I'm sorry, but beyond this point, it's not really a Unity question anymore. I highly recommend you watch or read some beginner program$$anonymous$$g tutorials.
Your answer
Follow this Question
Related Questions
Using AirBrakes on mobile device with Standard Assets AircraftController 0 Answers
why tansform.Translate is not working? 1 Answer
[C#] Save/Load Score stays at 0 even when changed 2 Answers
rigidbody.Use gravity not working from script 0 Answers
How to make the calculated angle respective of the players rotation? 1 Answer