Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 16, 2011 at 06:47 PM by CarlLawl for the following reason:

Other

avatar image
0
Question by CarlLawl · Jun 26, 2011 at 02:47 AM · functionsdialog

Running script/lines of code

At the moment I'm in the process of making a dialog system, but I'm a bit confused, before throwing up our dialog box with its text, say we want to move our npc before they say the next piece of dialog, what would be the best route to take for this?

I had the idea of making a new script called DialogFunctions which just contains a list of functions, then in the inspector you type in the function name, in which case it takes the variable in the case of a string and sendmessage the function.

 public string functionToExecute; // this gets filled in in the inspector
 
 void OnGUI () {
     if (functionToExecute != "") {
         gameObject.sendmessage(functionToExecute);
     }
     // continue with showing dialog
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0

Answer by hardcoded · Jun 26, 2011 at 04:28 AM

I'm not sure I understand the question. I'll answer the best I can -- it's my first time. Is this a part of a separate object that contains the OnGUI call.

Finding the right targetobject per function is another ball of wax that depends on your application. You could just make another public variable, tag the object(and use findByTag), name it a specific way, or some other way of singling out the object you want. ( http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html )

I'll assume that this is some Dialog subclass that gets created or activated when the dialog should be shown. If that is the case, then you just but the sendmessage call in the awake() or start() function.

If you are using some other system, then just use a boolean flag to indicate that you should in fact run that code once ie:

where otherDialogPrerequisite is whatever would cause your dialog to be shown and targetObject is the one you want to select.

bool hasRunBefore;

function OnGUI() { if(otherDialogPrerequisite == true && hasRunBefore == false){ hasRunBefore = true; targetObject.sendmessage(functionToExecute); } }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Save Dialogs 1 Answer

How to add play again or quit dialog 1 Answer

Cant Get Dialogue Trigger Working 0 Answers

problems accessing variables and functions in another script 1 Answer

What is the difference between InvokeRepeating & Invoke and how can they be used? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges