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 CameronSanders · Aug 08, 2013 at 06:44 AM · javascriptif statement

Why does my if statement skip its body?

My second if statement doesn't seem to want to read its body. it sends the debug, but everything else is skipped. can anyone explain why? lines 19,20, and 21 never happen. no errors in debug.

 #pragma strict
 
 var switchup = false;
 var lever : Transform;
 var distance = 0.0;
 var vision = 5.0;
 var player : Transform;
 
 function Start () {
 
 }
 
 function Update () {
         var click = Input.GetMouseButtonDown(0);
         distance = Vector3.Distance(lever.position, player.position);
         if (distance < vision && click) {
         if (switchup == false) {
         Debug.Log("has passed test, is false");
         switchup = true;
         lever.localPosition = Vector3(-0.01412122,0,0.3352401);
         lever.localRotation = Quaternion.Euler(0,47.94865,0);
         }
         else
         Debug.Log("reset to starting pos");
         switchup = false;
         lever.localPosition = Vector3(0.7541609,0,-0.05813695);
         lever.localRotation = Quaternion.Euler(0,310.3725,0);
     }
 }
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
Best Answer

Answer by robertbu · Aug 08, 2013 at 06:48 AM

You don't have any '{}' in your else statement, so lines 25-27 get executed regardless of the value of switchup. Only the 'Debug.Log()' statment is contingent on the 'else.' The result is that switchup gets set to false immediately after it has been set to true.

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 CameronSanders · Aug 08, 2013 at 07:16 AM 0
Share

thanks for the answer.

avatar image Joyrider · Aug 08, 2013 at 07:29 AM 0
Share

@CameronSanders : you should accept the answer by clicking the (V) below the thumbs-up and thumbs-down, so as to close the question.

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

15 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

Related Questions

What is causing my AI script to interpret wrong data? 1 Answer

GUI Counter Based on Animation or RaycastHit 0 Answers

Setting Scroll View Width GUILayout 1 Answer

(if statement) is acting weird 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers


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