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 Jul 12, 2014 at 10:10 AM by tanoshimi for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Reizen · Jul 11, 2014 at 10:56 PM · ifaccessingelse

İf-Else block doesn't react the condition

 public class TouchClass : MonoBehaviour {
 
 SliderScr slider;
     
     void Start(){
         slider = GameObject.Find("SlideMenu").GetComponent<SliderScr>();
     }
     
     void Update(){
 
         for(int i = 0; i < Input.touchCount; i++)
         {
             if(this.guiTexture.HitTest(Input.GetTouch(i).position))
             {
                 if(!slider.setUp)
                 {
                     //Not working...
                 }
                 
                 else if(slider.setUp)
                 {
                        //Not working...    
                             }
     void OnGUI()
     {
         GUI.Label(new Rect(50,50,50,50),slider.setUp.ToString());
     }

}

I've got a SliderScr script attached to a "SlideMenu" object and it has a boolean value "setUp". I can access to "setUp" and print its value with OnGUI from TouchClass but those condition blocks (if and else if) doesn' work. If i touch the "SlideMenu" object, it turns this "setUp" value to true and touch again its value turns into false. It's working as i want. So is there anyone who can tell me what i'm doing wrong? Why do these conditions not work?

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 fafase · Jul 11, 2014 at 10:59 PM 1
Share

So I reckon you built the game and tried on it on your device or you run it on the emulator.

Now how far do you get down in the ifs?

I can see you are missing } already but that could be a wrong typo:

 for(int i = 0; i < Input.touchCount; i++)
 {
    print("In for");
    if(this.guiTexture.HitTest(Input.GetTouch(i).position))
    {
        print("In Hit");
        if(!slider.setUp)
            print("Set up");
        else 
            print("No set up");
    }
 }
avatar image HolBol · Jul 11, 2014 at 11:05 PM 0
Share

Formatted answer to make the question look a bit better.

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Kiwasi · Jul 11, 2014 at 11:02 PM

Add a Debug.Log(slider.setUp) at line 11. (ie inside the first if statement, but not the second)

Possible results

  • The console shows nothing. This means your outer if is not working

  • The console shows something that is not true or false. This means that setUp is not a bool

  • The console shows null. This means you haven't got the reference correctly, or it hasn't been initialised

  • The console shows true or false. This means its working fine and you have messed up the coding somewhere else

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
avatar image
0

Answer by HolBol · Jul 11, 2014 at 11:03 PM

Well for starters you haven't closed the first if or the function, so you're missing two brackets. Also, you can just use else if you only need two cases rather than else if. Also, what is HitTest? Can't see where you've defined that either. We need a little more info about what you're trying to do first.

     public class TouchClass : MonoBehaviour {
     
     SliderScr slider;
     
     void Start(){
              slider = GameObject.Find("SlideMenu").GetComponent<SliderScr>();
         }
          
     void Update(){
          
         for(int i = 0; i < Input.touchCount; i++)
         {
            if(this.guiTexture.HitTest(Input.GetTouch(i).position))
            {
              if(!slider.setUp)
              {
                 //Not working...
              }
          
              else 
                {
              //Not working...
               }
           }
     }
 
   void OnGUI()
         {
         GUI.Label(new Rect(50,50,50,50),slider.setUp.ToString());
         }
     
     }

Comment
Add comment · Show 2 · 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 Bunny83 · Jul 12, 2014 at 01:25 AM 0
Share

HitTest

avatar image Reizen · Jul 12, 2014 at 09:57 AM 0
Share

Thank you all dudes (especially Bored$$anonymous$$ormon), i figured it out; setUp value was null and i made correction to get reference right. It's working now...

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help playing the right animation 1 Answer

Why am i getting this error?! 2 Answers

How to finish my else if statement? 2 Answers

For loop has 'if-else' impossibility. 2 Answers

I am getting error cs1525 for '}' on line 11,17. How come? 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