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 aqeel25 · Nov 09, 2021 at 10:24 AM · boolifupdate function

Update function is not executing the bool

I am using following update function

 bool Xpositive=false;
 float XAxiscurrentXpos;
 float izvalue;
 Vector3 XAxisposition;
 void Update()
 {
        if (Xpositive == true)
     {
             while (XAxiscurrentXpos <= -izvalue)
             {
                 XAxis.transform.localPosition += Vector3.right * 0.01f * Time.deltaTime;
             }
         }
         else
         {
             if (XAxiscurrentXpos > -izvalue)
             {
                 while (XAxiscurrentXpos >= -izvalue)
                 {
                     XAxis.transform.localPosition -= Vector3.right * 0.01f * Time.deltaTime;
                 }
             }
         }} }`


Now, the Xpositive is changed in following code

  public void ObjSupport_PositionArrived(string Coordinate, double Value)
     {
         switch (Coordinate)
         {
             case "X-":
                 { //X-code }
                 break;
             case "X+":
                 {   Xpositive = true; }
                
                 break;
  
             case "Z-":
                { //code for Z  }    break;
         }
     }}

Problem is that when Bool Xpositive is set to true ,the IF in Update still is not executed.

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 · Nov 09, 2021 at 12:00 PM 0
Share

You could try and debug the flow. Maybe the Update is run before the ObjSupport_PositionArrived is called and the Xpositive is reset at the end of the frame.

avatar image aqeel25 fafase · Nov 09, 2021 at 12:03 PM 0
Share

I am not resetting it .

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jmfp92 · Nov 09, 2021 at 10:31 AM

without even knowing for sure what the problem is, I'm willing to bet it's the while loop in your update function. Instead of using a while loop try doing this

 void Update() { 
     if (Xpositive  && XAxiscurrentXpos <= -izvalue){
         // the rest of the stuff you said

while loops are pretty expensive and should really only be used if it is absolutely the only option

Comment
Add comment · Show 7 · 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 aqeel25 · Nov 09, 2021 at 11:18 AM 0
Share

No that is not the issue. If the Xpositive become true in below function the Update should execute the if statement as condition becomes true

avatar image jmfp92 aqeel25 · Nov 09, 2021 at 11:23 AM 0
Share

Ok, I'm just a little confused as to why you aren't just running the code you need to happen if Xpositive is true in the switch case "X+". Instead of setting xpositive to true and then running the code elsewhere, just run the code inside of the case example:

 case "X+":
                  //{   Xpositive = true; }
                 //do the Xpositive stuff
                  break;


hopefully I don't sound like a jerk, I am just trying to understand

avatar image aqeel25 jmfp92 · Nov 09, 2021 at 11:39 AM 0
Share

Actually i was doing this Await Task.delay() .So someone suggested me alternative of this as above and now I am having this issue

Show more comments

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

130 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 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

A Button, A Boolean and 2 Textures. 2 Answers

OnTriggerEnter if else 2 Answers

How to stop the camera in a certain position? 1 Answer

how to use bool from another script in if statment? 2 Answers

Animator if Bool 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