Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Extending a function?

Discussion in 'Scripting' started by Fraeger, Jan 12, 2014.

  1. Fraeger

    Fraeger

    Joined:
    Nov 9, 2013
    Posts:
    9
    Hello,

    I am trying to make a little Dialogue System. So I created a function that creates buttons and that I can use in inherited classes
    (there are some functions in here that I havent posted like sayNPC(), but that shouldnt matter):

    Code (csharp):
    1.  function Button (_buttonNumber : int, _parentNumber : int, _Question : String, _Response : String, _Exit : boolean) { // draws the Buttons of a Dialogue
    2.    
    3.     var textTime = 2.0f;
    4.     var buttonNumber: int = _buttonNumber;
    5.     var Question: String = _Question;
    6.     var Response: String = _Response;
    7.     var Exit: boolean = _Exit;
    8.    
    9.     if (dialogueActive  displayButtons) {
    10.         if ( GUI.Button ( Rect (12,Screen.height -120 + ( buttonNumber * 32 ),Screen.width - 24 , 20 ), Question )) {
    11.             displayButtons = false;    
    12.             currLayer++;   
    13.             parentQuestion = _parentNumber;
    14.             sayPlayer (Question, textTime);
    15.             yield WaitForSeconds (waitTime);
    16.             sayNPC (Response, textTime);       
    17.             yield WaitForSeconds (waitTime);
    18.             if (Exit == true) {
    19.                 EndDialogue ();        
    20.             }
    21.             displayButtons = true;
    22.                                            
    23.         }
    24.        
    25.     }
    I use this like this in the inherited classes:

    Code (csharp):
    1. function OnGUI () {
    2.             Button (1,0,"Nevermind","Alright, see you buddy.", true);  
    3. }
    4.  
    Now, i would like to know if there is any way that I can add some functionality here. So for example in some cases, when the player presses a button, I want to set a variable in a different script of instantiate an Item or something.
    is there any way to add stuff like that within the if (GUI.button [...]) from calling the whole button function? (I hope you get what I mean)
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906