- Home /
[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: 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.
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
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;
}
}
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
Follow this Question
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