Search Unity

simple question - Possible to stop a function?

Discussion in 'Scripting' started by MBomberZ1, Aug 21, 2009.

  1. MBomberZ1

    MBomberZ1

    Joined:
    Jul 28, 2009
    Posts:
    65
    Thats basically it, is it possible to stop a function using a line of code inside of it self. Basically i have multiple if statements inside 1 function, and if the first one returns true, i need it to stop playing through the rest of them. I guess i could use if else for the rest? if there is a piece of code specifically for this, that would be much cleaner in my mind. Thanks!
     
  2. cosmicmesh

    cosmicmesh

    Joined:
    Mar 19, 2009
    Posts:
    61
    You just call "return" early. You can also "break" from if statements...

    Code (csharp):
    1.  
    2. if{test == true)
    3. {
    4. foo.bar();
    5. return;
    6. }
    7. else if
    8. {
    9. foo.bar2();
    10. return;
    11. }
    12.  
     
  3. MBomberZ1

    MBomberZ1

    Joined:
    Jul 28, 2009
    Posts:
    65
    Aawesome, thank you very much for the help.