• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by the_game_maker · Jun 12, 2015 at 07:41 PM · c#unity 5scripting problem

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FortisVenaliter · Jun 12, 2015 at 07:48 PM 0
Share

Please post the code that calls the Choice function.

avatar image the_game_maker · Jun 12, 2015 at 07:57 PM 0
Share

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");
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image the_game_maker · Jun 12, 2015 at 08:08 PM 0
Share

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

avatar image FortisVenaliter · Jun 12, 2015 at 08:10 PM 0
Share

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.

avatar image the_game_maker · Jun 12, 2015 at 08:19 PM 0
Share

I'm starting to get the error:

error CS1501: No overload for method Choice' takes 2' arguments

avatar image FortisVenaliter · Jun 12, 2015 at 08:33 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Refresh panel with prefab contained value from json that created using array 0 Answers

Object reference not set to an instance of an object 1 Answer

My sphere is not moving in the unity? 1 Answer

MoveTowards issue, animating ui. 1 Answer

How do I make the winning racer get a text saying Congrats? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges