Quick question

bool transition = true;

//switch

void OnCollisionEnter(Collision other)

{

if(transition){   return;  }

switch(other.gameObject.tag)

{

case “Friendly”:

break;

case “Finish”:

WinLevel();

break;

default:

Crash();

break;

}

}

//delay before next level

void WinLevel()

{

    //add victory particles

    transition = false;

    GetComponent<AudioSource>().PlayOneShot(Victory);

    goLimp = GetComponent<MoveRocket>();

    goLimp.enabled = false;

    Invoke("NextLevel",nextLevelDelay);

}

ok so it took a while but I finally realized that when transition is true you can run switch statements, and when you call a method that has transition = false it changes the bool variable to false meaning it cant run the switch statements but what I want to know is what is the significance of return? is it just to end the if statement if so why is it their when transition is true if the transition is true shouldn’t the return stop the if statement from even running, also how come the if statement works without wrapping the conditions in brackets I know what I’ve said sounds really confusing and my apologies but I’m really stuck and trying to understand the script works I just really want to know how it works.

return is a keyword that basically stops running the method and return control back to the method that called it… so yes, it’s to end the whole method, not just that statement.

Hope that helps.

Yeah I get it now, thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms