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 StartUpStudios · Sep 26, 2014 at 07:58 PM · androidgame

Problem with if statement logic- Need help!

I'm trying to get my main menu working properly. I have three chapter selectors. When selected, each will active a different camera with the proper chapter backgrounds. Each chapter's camera's culling masks are set to only see the GUITexture for that specific chapter's levels. This works great. Back button brings me back to the main menu. it's all working how I want. problem is, no matter what method I use, i cannot get the GUITexture buttons to STOP WORKING. See>

In Main Menu- Main Menu Buttons(Yes)/Chapter1 Buttons(No)/Chapter2 Buttons (No)/Chapter3 Buttons(no)

In Chapter 1- Chapter1 (yes)/Main Menu Buttons(no)/Chapter2 (no)etc....

In Ch2- Ch 2(yes)/Main M(no)/CH1 (no)/etc...

That logic seems sound, right? But whether I use guiTexture.enabled=true/false; NO effect. Ok, just wrap the level select code in an if statement right? such as if(canClickCH1==true){ Allow clicking of chapter 1 levels }

DOESN'T WORK. No matter how I arrange my If statements. The code below is the code I use for Chapter 1 level select. (Same for chapter 2, but the variable names are changed) yet it's not working. At all. There's got the be something wrong with my logic somewhere. Can someone help me figure this out? It's been driving me crazy for days. thanks for your time. I just want to disable all the GUITexture buttons I'm not suing in the moment and only be able to click the ones I do want to use. (This is messy code with a lot blocked out. That's either for testing ir something I haven't deleted yet. Sorry.)

 public var IsChapter : int;
 
 public var Ch1unlocked : boolean = false;
 
 var levelTex : Texture2D;
 //static var chooseCHlvl : int;
 public var levelToLoad : int;
 static var can1 : boolean = false;
 public var canClick : boolean;
 public var canGo : boolean = false;
 
 var Camera2 : Camera;
 
 function Start () {
 can1=false;
 guiTexture.enabled = false;
 }
 
 function Update () {
 canClick = can1;
 
 
 guiTexture.texture = levelTex;
 
 
 AutoResize(1920, 1080);
 
 
 
 /*if(thisLevel == PlayerPrefs.GetInt("CH1lvl2")){
 Ch1unlocked = true;
 }
 if(thisLevel == PlayerPrefs.GetInt("CH1lvl3")){
 Ch1unlocked = true;
 }
 if(thisLevel == PlayerPrefs.GetInt("CH1lvl4")){
 Ch1unlocked = true;
 }
 if(thisLevel == PlayerPrefs.GetInt("CH1lvl5")){
 Ch1unlocked = true;
 }
 if(thisLevel == PlayerPrefs.GetInt("CH1lvl6")){
 Ch1unlocked = true;
 }
 if(thisLevel == PlayerPrefs.GetInt("CH1lvl7")){
 Ch1unlocked = true;
 }
 */
 
 
 
 if(can1 == true){
 guiTexture.enabled = true;
 for (var i = 0; i < Input.touchCount; ++i)
        {
       
             if(guiTexture.HitTest(Input.GetTouch(i).position)){
                    if (Input.GetTouch(i).phase == TouchPhase.Began) 
                {
                         if(Input.GetTouch(i).tapCount == 1)
                         {
                        //if(can1==true){
                        can1=false;
                          chooseLevel();
                        // }
                         }
        }
        }
        }
        }
        
        
       
        
      /*  if (guiTexture.HitTest(Input.mousePosition)) {
         if(can2 == true){
         choose2Level();
         }
         if(can1 == true){
         chooseLevel();
         }
         
        }*/
        
        }
        
        public static function AutoResize(screenWidth:int, screenHeight:int):void
 {
     var resizeRatio:Vector2 = Vector2(Screen.width / parseFloat(screenWidth), Screen.height / parseFloat(screenHeight));
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(resizeRatio.x, resizeRatio.y, 1.0));
 }
 
 /*function FadeIn(){
 //yield Fade(0.0, 1.0, 1);
 
 if(Ch1unlocked==true){
 yield Fade(0.0, 1.0, 1);
 }
 if(Ch1unlocked==false){
 yield Fade(0.0, 0.5, 2.0);
 }
 }*/
 
 function chooseLevel(){
 can1=false;
 Application.LoadLevel (levelToLoad);
 }
 
 function FadeUnlocked(){
 yield Fade(0.0, 1, 1);
 }
 
 function Fade (startLevel :float, endLevel :float, duration :float) {
         var speed : float = 0.3/duration;  
         for (var t :float = 0.0; t < 1.0; t += Time.deltaTime*speed) {
             guiTexture.color.a = Mathf.Lerp(startLevel, endLevel, t);
             yield;
         }
     }



Comment
Add comment · Show 3
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 Baste · Sep 26, 2014 at 08:12 PM 2
Share

The code you've posted is really messy, and it's kinda hard to get a grip on it. I'd recommend removing the commented out stuff, and get your IDE (like $$anonymous$$onodevelop) to indent your code properly!

It's also not quite clear what the problem is - does the GUI texture of the buttons not disappear when you disable the button? Or are they invisible but clickable?

avatar image Addyarb · Sep 26, 2014 at 08:49 PM 0
Share

Agreed with comment above, rephrase your question and repost simplified version of your code please! Wishing you luck.

avatar image StartUpStudios · Sep 26, 2014 at 09:04 PM 0
Share

Sorry Lads. Cleaned up Code below. $$anonymous$$y problem is not that they go invisible. (using the culling masks eli$$anonymous$$ates the need for that) The problem is that they're clickable when they shouldn't be. When I'm in the main menu, I can still click the level buttons. When I'm choosing a level, I can still click the chapter buttons. When I shouldn't be able to. Thanks for the help guys.

 var levelTex : Texture2D;
 static var chooseCHlvl : int;
 public var levelToLoad : int;
 static var can1 : boolean = false;
 public var canClick : boolean;
 
 
 var Camera2 : Camera;
 
 function Start () {
 can1=false;
 guiTexture.enabled = true;
 }
 
 function Update () {
 canClick = can1;
 
 
 guiTexture.texture = levelTex;
 
 guiTexture.enabled = true;
 for (var i = 0; i < Input.touchCount; ++i)
        {
       
             if(guiTexture.HitTest(Input.GetTouch(i).position)){
                    if (Input.GetTouch(i).phase == TouchPhase.Began) 
                {
                         if(Input.GetTouch(i).tapCount == 1)
                         {
                     if(can1 == true){
                        can1=false;
                          chooseLevel();
                           }
                      
                         }
        }
        }
        }
        
        }
        
   
 
 
 
 function chooseLevel(){
 can1=false;
 Application.LoadLevel (levelToLoad);
 }
 
 function FadeUnlocked(){
 yield Fade(0.0, 1, 1);
 }
 
 function Fade (startLevel :float, endLevel :float, duration :float) {
         var speed : float = 0.3/duration;  
         for (var t :float = 0.0; t < 1.0; t += Time.deltaTime*speed) {
             guiTexture.color.a = $$anonymous$$athf.Lerp(startLevel, endLevel, t);
             yield;
         }
     }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Habitablaba · Sep 26, 2014 at 10:53 PM

Here is a collapsed and reformatted version of your checks from the Update method.

 for (var i = 0; i < Input.touchCount; ++i)
 {
   if(guiTexture.HitTest(Input.GetTouch(i).position)
     && Input.GetTouch(i).phase == TouchPhase.Began
     && Input.GetTouch(i).tapCount == 1
     && can1)
   {
     can1=false;
     chooseLevel();
   }
 }
  

It looks to me like this should work, which causes me to look elsewhere.
Namely:

 static var can1 : boolean = false;

Why is this static? Where else is this being set?

Comment
Add comment · Show 1 · 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 StartUpStudios · Sep 26, 2014 at 11:10 PM 0
Share

When the "Chapter 1" button is pressed from the main menu, it's called from the mainGUI script I use and can1 is supposed to be set to true. Then if you go back from the level select screens to the $$anonymous$$ain menu (switching cameras), it is set to false. Which works great. For both Chapter 1 and 2. Which is why I'm so confused as to why it's not working.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Problem with acclerometer 0 Answers

Problem with jcar script for android mobile 1 Answer

Pause Android game- menu pop-up? 1 Answer

Run a VR game with PC & Google Cardboard?? 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