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 BluetheFox · Sep 10, 2016 at 08:42 AM · if statementno error

if statement being completely ignored c#

 using UnityEngine;
 using System.Collections;
 
 public class Clickvalve : MonoBehaviour
 {
 
     // From the inspector, add the player GameObject on this script's field
     public Transform Player;
     // Exact same thing as player
     public Transform Box;
     // Set the desired interaction distance value
     public float InteractionDistance = 10;
     // Setting up the "playing" variable
     bool playing;
     // Setting up a public variable to be referenced by another script later
     public static int Valvepressure = 10;
     //following section updates every single frame
     void Update()
     {
         //if the animation is playing...
         if (GetComponent<Animation>().IsPlaying("Valve_turnright"))
         { //...then set "playing" to true
             playing = true;
         }
         else //otherwise...
         { //...set it to false.
             playing = false;
         }
     }
 
     //now, when I press the mouse button...
     void OnMouseDown()
     { //Playerdist is defined as the distance between player and box
         float Playerdist = Vector3.Distance(Box.position, Player.position);
         //then if the player distance is less than the interaction distance and the animation isnt playing...
         if (Playerdist < InteractionDistance & !playing);
         {// it should do all this. and it does...but for some reason, it skips the if statement. 
             GetComponent<Animation>().Play("Valve_turnright");
             GetComponent<AudioSource>().Play();
             if (Valvepressure > -6)
             {
                 Valvepressure = Valvepressure - 1;
             }
 
             Debug.Log("Valve pressure is now" + Valvepressure + "!");
         }
     }
 }
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
1
Best Answer

Answer by unityGecko · Sep 10, 2016 at 10:45 AM

You have a semicolon in line 37, right after the if-condition. Thus, the C# compiler thinks your if-statement has an empty body and moves on to the next line.

Just delete the semicolon and it should run just fine.

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 BluetheFox · Sep 10, 2016 at 03:08 PM 0
Share

works perfectly! thanks!

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

Zombie Attack Animation script 1 Answer

no idea what is wrong 0 Answers

how to reset jump everytime it hits ground not when it is constantly on the ground 0 Answers

If & Else If with == and && not working 0 Answers

Unexpected token: if HELP 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