Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 question was closed Aug 03, 2020 at 04:57 PM by gf457767 for the following reason:

The problem was simple and I found out for myself how to fix it

avatar image
0
Question by gf457767 · Jul 30, 2020 at 03:41 PM · uibooleanif-statementsactivationbooleans

How to activate a panel by a toggle using a script?

I am creating a project about artistic gymnastics,it is a text-based game,it doesn't have any 3d models or anything. I created a panel that contains toggles,these toggles tell if the aparatus will be used or not(for now just the vaulting table toggle works). If the toggle is activated the "VaultPanel" is activated when the next button is clicked,but if is not the panel should not be activated when you click on the next button,but for some reason,the opposite is happening: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class ToggleSelection : MonoBehaviour {
 
   public Toggle VaultToggle;
   public Button NextButton;
   public GameObject VaultPanel;
   public GameObject UnevenBarsPanel;
   public GameObject AparatusSelectionPanel;
 
     void Start()
     {
       NextButton.onClick.AddListener(isVaulting);  
     }
 
      void isVaulting()
     { 
       if(VaultToggle == true)
       { 
         AparatusSelectionPanel.gameObject.SetActive(false);
         VaultPanel.gameObject.SetActive(true);
       }
        if(VaultToggle == false)
         {
          AparatusSelectionPanel.gameObject.SetActive(false);
          VaultPanel.gameObject.SetActive(false);
          UnevenBarsPanel.gameObject.SetActive(true);
         }
       }
     }

(The uneven bars panel should be activated if the vaultToggle is false,but the opposite is happening)

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1

Answer by jmailloux11 · Jul 30, 2020 at 08:21 PM

VaultToggle.gameObject.SetActive(!VaultToggle.gameObject.activeSelf); UnevenBarsPanel.gameObject.SetActive(!VaultToggle.gameObject.activeSelf);

Sould do the trick.

Just replace the if statements to be this part of code.

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 jmailloux11 · Jul 30, 2020 at 08:22 PM 0
Share

Also is the AparatusSelectionPanel supposed to be set false at all time?

you wrote "AparatusSelectionPanel.gameObject.SetActive(false);" twice!

avatar image gf457767 jmailloux11 · Jul 31, 2020 at 10:03 AM 0
Share

The aparatus selection panel should be deactivated in both cases beacause when I press the next button the panel should close and open the next one than can be the vault panel or the uneven bars panel depending if the vaulttoggle is true or false

avatar image gf457767 jmailloux11 · Jul 31, 2020 at 05:49 PM 0
Share

It didn't work,if the toggle is activated the uneven bars panel is called and if it's not the uneven bars panel still is called

avatar image gf457767 jmailloux11 · Jul 31, 2020 at 05:54 PM 0
Share

@jmailloux11 Actually what do I do? Do I put this code in the condition or the condition action

Follow this Question

Answers Answers and Comments

135 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scavenger Hunt List Bools Question 1 Answer

Display issues with GUI only showing details for last object in list. 2 Answers

Boolean on if statement not working 2 Answers

Booleans are "asssigned but never used"??? 1 Answer

How do you Manage Multiple Boolean Better, I know I'm supposed to use a foreach but I have no idea how that works 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