c# - I want to create a dialog box, call a class on click in unity -


i want create dialog box, used script dialog.cs. want call script, example, want click object , make appear windows dialog. unfortunatly, when click object windows dialog doens't appear.

ps: since dialog script monobehaviour, added object display it.

gameobject.addcomponent<dialog>(); 

full dialog.cs

using unityengine; using system.collections.generic;  public class dialog : monobehaviour {      public textasset conversationasset;      protected string dialogname="";     public string description="";     public bool keytriggered=true;     public bool restartdialogeachtime=true;     public string triggerinputkey="chat";     public string dialogclass="dialogguibasic";     public float dialogrange=3;     public guiskin dialogskin;     public camera dialogcamera=null;     public vector2 dialogsize=new vector2(800,371);     public texture2d dialogportrait=null;     public float characterspersecond=50f;      private conversation[] conversations=null;     private int conversationindex=0;     private gameobject playerobject;      public void start(){         loaddialog();         playerobject=gameobject.findwithtag("player");          // add parley list         parley.getinstance().getdialogs().add(dialogname,this);     }      public int getconversationindex(){         return conversationindex;     }      public void setconversationindex(int conversationindex){         this.conversationindex=conversationindex;     }      public conversation[] getconversations(){         return conversations;     }      protected void loaddialog(){         dialogname=conversationasset.name.substring(4);         debug.log("name=["+dialogname+"]");         // load text asset         string[] lines = conversationasset.text.split("\n"[0]);         int l=0;          conversations=new conversation[int.parse(lines[l++])];          (int c=0;c<conversations.length;c++){             l++;             conversation co=new conversation();             conversations[c]=co;              co.id=int.parse(lines[l++]);             co.returnid=int.parse(lines[l++]);             co.returndialogname=lines[l++];             co.text=null;                        (string text=lines[l++];!text.equals(conversation.break);text=lines[l++]){                 if (co.text!=null){                     co.text+="\n";                 }                 co.text+=text;             }              co.repeattext=null;             (string text=lines[l++];!text.equals(conversation.break);text=lines[l++]){                 if (co.repeattext!=null){                     co.repeattext+="\n";                 }                 co.repeattext+=text;             }              co.once=bool.parse(lines[l++]);             co.fallthrough=bool.parse(lines[l++]);             co.questevent=lines[l++];              co.playercommands=new command[int.parse(lines[l++])];             (int ct=0;ct<co.playercommands.length;ct++){                 command command=new command();                 co.playercommands[ct]=command;                  command.objectname=lines[l++];                 command.method=lines[l++];                 command.assignment=("true".equals(lines[l++]));                 command.paramaters=new string[int.parse(lines[l++])];                 (int pt=0;pt<command.paramaters.length;pt++){                     command.paramaters[pt]=lines[l++];                 }             }              co.questrequirement=lines[l++];             co.environmentalrequirement=lines[l++];             co._available=bool.parse(lines[l++]);              if (co.repeattext==null || co.repeattext.length==0) co.repeattext=null;             if (co.questevent==null || co.questevent.length==0) co.questevent=null;             if (co.playercommands==null || co.playercommands.length==0) co.playercommands=null;             if (co.questrequirement==null || co.questrequirement.length==0) co.questrequirement=null;              co.options=new option[int.parse(lines[l++])];              (int n=0;n<co.options.length;n++){                 l++;                 option o=new option();                 co.options[n]=o;                 o.text=lines[l++];                 (string text=lines[l++];!text.equals(conversation.break);text=lines[l++]){                     if (o.text!=null){                         o.text+="\n";                     }                     o.text+=text;                 }                   o.destinationid=int.parse(lines[l++]);                 o.destinationdialogname=lines[l++];                 o._available=bool.parse(lines[l++]);                 l++;             }             l++;         }     }      public void update(){         if (triggerinputkey!=null && triggerinputkey.length>0 && keytriggered && input.getbuttonup(triggerinputkey) && isinrange() && !parley.getinstance().isingui()){             triggerdialog();         }     }      public bool isinrange(){         return vector3.distance(transform.position, playerobject.transform.position)<dialogrange;      }      public void triggerdialog(){         triggerdialog(restartdialogeachtime?0:conversationindex);     }      public void triggerdialog(int start){         conversationindex=start;         if (dialogclass!=null && dialogclass.trim().length>0){             // make sure ever add 1 gui instance             monobehaviour dialogguiinstance=(monobehaviour)getcomponent(dialogclass);             if (dialogguiinstance==null){                 // add dialog gui                 gameobject.addcomponent<dialog>();             }         }         sendmessage("startdialog",this,sendmessageoptions.requirereceiver);     }      public void triggerdialogend(){         if (dialogclass!=null && dialogclass.trim().length>0){             monobehaviour dialogguiinstance=(monobehaviour)getcomponent(dialogclass);             if (dialogguiinstance!=null){                 // delete dialog gui script                 destroy(dialogguiinstance);             }         }     }      public void ondrawgizmos(){         if (conversationasset!=null){             gizmos.drawicon (transform.position-new vector3(0,-dialogrange/3,0),"parleydialog.png");         }     }      public void ondrawgizmosselected () {         if (conversationasset!=null){             gizmos.color = color.yellow;             gizmos.drawwiresphere (transform.position, dialogrange);         }     } 

unity 5 has breaking api changes.

instead of auto converted line looks like:

unityengineinternal.apiupdaterruntimeservices.addcomponent(gameobject, "assets/parley assets/scripts/dialog.cs (150,5)", dialogclass); 

unity has blog post api change here

//this add dialog, so, , window show up! gameobject.addcomponent<dialog>(); 

since dialog script monobehaviour, added object display it.

but doesn't display windows dialog when click on object.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -