Search Unity

how to script something like this ?

Discussion in 'Scripting' started by karammaks, Apr 25, 2015.

  1. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    i want to do something like if this function is executed , bla bla bla , like this

    if (function()){
    .....
    .....
    }

    if the function is executed do what inside in this if, i know its wrong to use that way , but how to do it correctly ???
     
  2. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Code (csharp):
    1.  
    2. bool Func()
    3. {
    4.     // Condition here
    5.     return true;
    6. }
    7.  
    8. void OtherFunc()
    9. {
    10.     if (Func())
    11.     {
    12.         // bla bla
    13.     }
    14. }
    15.  
    Something like that?
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This is exactly the right way to do it, as long as the return type of your function is a bool.