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 /
avatar image
0
Question by Speed_1 · Sep 02, 2018 at 06:57 PM · scripting problemscripting beginner

[SOLVED] According to "print" message boolean variable turns true but if statment doesn't do stuff.,

I need an if statment to Start Coroutine so I create one. And it doesn't working. After I use print function to see the boolean variable really always false. I see it turns true normally. But still if statment doesn't do stuff. This is code (in void Uptade):`

     if (p1.calisti || p2.calisti2)
     {
        
         if (oynat) return;
         else
         {
             StartCoroutine(OyunBitti());
             oynat = true;
         }

     }`

Here is the output of print(p1.calisti) in void Uptade:alt text I am noob. Sorry, if I miss little thing. Thank you.

,

My Solution: I change "if(p1.calisti || p2.calisti2)" statement's method Uptade to FixedUptade.Because in Uptade method statment called only once. But in FixedUptade (or LateUptade) it works very well.

p1-calisti.jpg (21.8 kB)
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 fr0stsp1k3 · Sep 02, 2018 at 07:22 PM

Well i dont know what your code says - and i'd need to see more to be able to understand it. But im sure you're aware that the method returns - so if is already true then it would just not start the coroutine - however, since you have said it to false- then it runs and starts a coroutine, basically a thread, and sets it to true - maybe its the order in which you do things? Try put the true before the coroutine? Just a guess.

But again, without seeing more thats my best guess

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 Speed_1 · Sep 02, 2018 at 09:24 PM 0
Share

1- In player script(p1) I create a void OnTriggerEnter and create if statment that is if player collide with "Zehirli" or "Zehirli3" gameObject with player script is disabled

 private void OnTriggerEnter(Collider collision)
     {
 
         if(collision.gameObject.tag == "Zehirli" || collision.gameObject.tag == "Zehirli3")
         {
             deathSound.Play();
             gameObject.SetActive(false);
              
         }
     }

2-I create void OnDisable.If first run create and destroy ParticleSystem ,after calisti[same bool in other script(p1.calisti)] returns true.

 private void OnDisable()
     {
         if (calisti) return;
         else
         {
             Destroy(Instantiate(olumPartikul, new Vector3(transform.position.x + 0.2f,transform.position.y + 0.2f, transform.position.z * 2.2f), transform.rotation), .4f);
             calisti = true;
         }
     }

avatar image Speed_1 · Sep 02, 2018 at 09:27 PM 0
Share

3-I create if statement in other script, too. It's if calisti or calisti2(same thing with calisti but it belongs to p2 script) and first run time starts coroutine.(in void Uptade())

   if (p1.calisti || p2.calisti2)
         {
             
             if (oynat) return;
             else
             {
                 StartCoroutine(OyunBitti());
                 oynat = true;
             }
 
         }

4- here is the IEnumerator function:

 IEnumerator OyunBitti()
     {
         oyunBitti.SetActive(true);
         anims[3].CrossFade("Black A 1");
         yield return new WaitForSeconds(.5f);
         anims[4].CrossFade("Text A 1");
         yield return new WaitForSeconds(.3f);
         anims[5].CrossFade("Button A 1");
         yield return new WaitForSeconds(.05f);
         anims[6].CrossFade("Button Text A 1");
         Cursor.visible = true;
     }

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

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

Script executing through walls 1 Answer

If-else statement executing incorrectly in foreach loop,why? 0 Answers

Linking Image to item list 1 Answer

How would I access my list from another function? 1 Answer

Random switch enum with a delay 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