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 /
avatar image
0
Question by Smyw3 · Jul 06, 2014 at 01:57 PM · sounddisableswitchbool

How to disable a bool switch under certain circumstances?

Hey everybody,

For days I am looking how to solve this, without any success. I am trying to switch Sound on and off with a bool var. This actually works quit well. The problem is that I have four buttons that I can combine for different actions. So in my case, I would press button2 to enable certain possibilities . When I keep it pressed and now press button1 I can switch my sound on(or off(via bool)). That works well. If the sound is playing and I now press button3 I enable a Nightmode, that still works fine. But if I press button1 again and enable a "Night Action" the Soundbool turns on and off. But the sound should continue. The other way round works perfect. So if I enable the Nightmode first and then trigger the Night Action the sound keeps disabled. So I somehow need to disable the bool for the first possibility. This is my script which is attached to a master script:

 using UnityEngine;
 using System.Collections;
 
 public class KlassikScript : MonoBehaviour {
     public Masterscript masterParent;
 
     public AudioClip klassiko;
 
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (masterParent.Song1Enabled == false){
             audio.Play();
             audio.loop = true;
         }
 
         if(masterParent.NachtErst == true){
             masterParent.Song1Enabled =false;
             audio.Stop();
         }
     }    

}

This is the part from the Masterscript:

 else if(pinValue1 == 1 && pinValue2 ==1 && pinValue3 == 0 && pinValue4 == 0){
             if(zweiterButtonZuerst == true){             //if button2 pressed first
                 Song1Enabled = !Song1Enabled;
             }
         }


I hope anybody has an idea what I might add?! Since it is a part of my final exam I really would appreciate your help!!! :-) Thanks!

Comment
Add comment · Show 1
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 SirCrazyNugget · Jul 06, 2014 at 02:49 PM 0
Share

Does each bool really need to rely on the others? From the looks of what you're trying to do they should all be independent allowing you to use individual if statements without any && operators.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jul 06, 2014 at 03:00 PM

If there are three buttons, there are 8 combinations of on/off. Just list them all, on paper, and figure what settings do what. Then code && and || to solve it. Any decent 1st semester programming textbook will go into more detail.

Suppose you need A and B pressed, and C not pressed, to do something. Write: if(A && B && !C).

I'm using !B instead of B==false, since it does read easier. You'd pronounce if(A && !B) as "if A and not B", which is shorter as just as good as "if A is true and B is false."

Suppose A does something, unless B and C are both pressed. Then use if(A && !(B && C)). If that logic is too much, list the combinations by hand: if(A&&!B&&!C || A&&!B&&C || A&&B&&!C)

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

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Gun Switch and SetActive is not Working! 2 Answers

Bool activate/de-activate on timer C# 1 Answer

Disabling first actor when switching to another camera. 0 Answers

How to destroy an object with sound? 2 Answers

How to stop landing sound when GameObject is grounded ? 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