Saturday, June 25, 2011

unity3d simple dialogue script



var honey_num = 0;
var MessageBoxText : String;
var showText : boolean = false;
var showText2 : boolean = false;
var notshowText2: boolean = false;

function OnControllerColliderHit(hit:ControllerColliderHit)
{   
    if(hit.gameObject.tag == "cube")
    {   
        
        Debug.Log("Zam Gets a HoneyComb");
       // Destroy(hit.gameObject);
        honey_num++;
showText = true;
        
    }
}


function Update () {
 endialogue();
}

function OnGUI() {
       
 if (showText)
    {


    GUI.BeginGroup (new Rect (Screen.width / 2 - 640, Screen.height / 2 - 360, 1280, 720));



    GUI.Box(new Rect (100, 500, 1080, 200),
    MessageBoxText + "\n\n Press F to continue...");

    GUI.EndGroup ();

    if(Input.GetKeyDown(KeyCode.F)){
    Deactivate();
showText2=true;
    }

    }
    
if(showText2)
    {


    GUI.BeginGroup (new Rect (Screen.width / 2 - 640, Screen.height / 2 - 360, 1280, 720));



    GUI.Box(new Rect (100, 500, 1080, 200),
    "Hello AMR" + "\n\n How are you...");
 
     notshowText2=true;
    GUI.EndGroup ();
  }
  
  
  
  
  
  //GUI.Box(Rect(0,0,100,100),"Hello AMR");
 
    //GUI.Label (Rect (10, 10, 100, 20), "Hello World!");
 
}



function Active(){
return showText;
}

function Deactivate(){
yield WaitForSeconds(0.1);
showText = false;
}

function endialogue(){

  if(notshowText2)
  {
  
   yield WaitForSeconds(2);
showText2=false;
   notshowText2=false;
  }


}



No comments:

Post a Comment