Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by HalfCarrot · Jan 07, 2017 at 06:29 PM · if statementnested

i need to check which object (playing piece) the user has clicked on...but the problem is the else if block does not seem to detect the mouse input.

sorry i forgot the braces..

     void Update () {
                 if (chance == 1) {
                     if (Input.GetKeyUp (KeyCode.Space)) {
                         if (enableInput == true) {
                             enableInput = false;
                             markers [0].gameObject.SetActive (true);
                             markers [1].gameObject.SetActive (false);
                             markers [2].gameObject.SetActive (false);
                             markers [3].gameObject.SetActive (false);
                             a.PlayOneShot (s_Dice);
                             DiceRoll ();
                             if (subPlayer == 4 && diceno == 6) {
                                 Vector3 temp;
                                 Vector3 currentPos;
                                 subPlayer -= 1;//3
                                 temp = transform.position;
                                 subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
                                 Invoke ("waitandgo",0.5f);
                             } else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6) {
                                     //print ("clicked");
                                     //ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                                     //if (Physics.Raycast (ray, out hit))// {
                                     print("Click");
         }
         }
         }
         }
         }
 
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

· Add your reply
  • Sort: 
avatar image
0

Answer by TBruce · Jan 07, 2017 at 07:57 PM

You are missing 4 closing braces } which should cause errors. If you just did not add them to your question then please add them to your question.

If I just add 3 closing braces } to the end of your script then this is what your code looks like

 void Update ()
 {
     if (chance == 1)
     {
         if (Input.GetKeyUp (KeyCode.Space))
         {
             if (enableInput == true)
             {
                 enableInput = false;
                 markers [0].gameObject.SetActive (true);
                 markers [1].gameObject.SetActive (false);
                 markers [2].gameObject.SetActive (false);
                 markers [3].gameObject.SetActive (false);
                 a.PlayOneShot (s_Dice);
                 DiceRoll ();
                 if (subPlayer == 4 && diceno == 6)
                 {
                     Vector3 temp;
                     Vector3 currentPos;
                     subPlayer -= 1;//3
                     temp = transform.position;
                     subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
                     Invoke ("waitandgo",0.5f);
                 }
                 else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6)
                 {
                     //print ("clicked");
                     //ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                     //if (Physics.Raycast (ray, out hit))
                     {
                         print("Click");
                     }
                 }
             }
         }
     }
 }

But the code above will not see the mouse click. You are probably looking for something moe like this

 void Update ()
 {
     if (chance == 1)
     {
         if (Input.GetKeyUp (KeyCode.Space))
         {
             if (enableInput == true)
             {
                 enableInput = false;
                 markers [0].gameObject.SetActive (true);
                 markers [1].gameObject.SetActive (false);
                 markers [2].gameObject.SetActive (false);
                 markers [3].gameObject.SetActive (false);
                 a.PlayOneShot (s_Dice);
                 DiceRoll ();
                 if (subPlayer == 4 && diceno == 6)
                 {
                     Vector3 temp;
                     Vector3 currentPos;
                     subPlayer -= 1;//3
                     temp = transform.position;
                     subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
                     Invoke ("waitandgo",0.5f);
                 }
             }
         }
         else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6)
         {
             //print ("clicked");
             //ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             //if (Physics.Raycast (ray, out hit))
             {
                 print("Click");
             }
         }
     }
 }
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 HalfCarrot · Jan 07, 2017 at 08:12 PM 0
Share

i edited it..but it still does not detect the mouse input

avatar image TBruce HalfCarrot · Jan 07, 2017 at 08:51 PM 0
Share

I added some debug code to your script so you can see where the problem lies (take a look at the console).

 void Update ()
 {
     if (chance == 1)
     {
         Debug.Log("chance = " + chance);
         if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.Space))
         {
             Debug.Log("Space key pressed");
             if (enableInput == true)
             {
                 Debug.Log("enableInput i true, setting it to false");
                 enableInput = false;
                 markers [0].gameObject.SetActive (true);
                 markers [1].gameObject.SetActive (false);
                 markers [2].gameObject.SetActive (false);
                 markers [3].gameObject.SetActive (false);
                 a.PlayOneShot (s_Dice);
                 DiceRoll ();
                 if (subPlayer == 4 && diceno == 6)
                 {
                     Debug.Log("subPlayer is equal to 4 and diceno is equal to 6");
                     Vector3 temp;
                     Vector3 currentPos;
                     subPlayer -= 1;//3
                     temp = transform.position;
                     subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
                     Invoke ("waitandgo",0.5f);
                 }
             }
         }
         else if (Input.Get$$anonymous$$ouseButtonDown(0))
         {
             Debug.Log("Left mouse button was clicked");
             if (subPlayer == 3 && diceno == 6)
             {
                 Debug.Log("subPlayer is equal to 3 and diceno is equal to 6");
                 //print ("clicked");
                 //ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                 //if (Physics.Raycast (ray, out hit))
                 {
                     print("Click");
                 }
             }
             else
             {
                 Debug.Log("subPlayer must be equal to 3 and diceno must be equal to 6 to enter the block above");
             }
         }
     }
     else
     {
         Debug.Log("is not equal to 1, chance is equal to " + chance + ". chance must be equal to 1 to enter the block above");
     }
 }

In your original code the following needs to be true to enter the block with the print statement

  1. chance must be equal to 1

  2. the left mouse button needs to be clicked

  3. subPlayer must be equal to 3

  4. diceno must be equal to 6

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

86 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

Related Questions

Adding to List of Nested Classes 1 Answer

C# If string is equal to any in array 2 Answers

If/ElseIf never reaches elseif 0 Answers

The If statement condition is false but the if statement stills executes 1 Answer

If/else statement is always else 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