Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Mrknztrk · Jan 31 at 09:20 AM · textunityeditorinspectorstringscriptableobject

Variables In Editor Inspector Strings

Hello everyone, it's probably pretty simple thing, I know. But I have two problems. The first one is, let's say.

 public class Player
 public string playerName;  //And let's say playerName is "Jack"

So when I try to manually write this playerName into Text Input of TextMeshProUGUI in editor, it doesn't show its value. the way I try to do is to write in editor text input " Player Name is : Player.Instance.playerName " I know it's not the way to do it, but you get the idea, is there a way to achieve what I'm trying to do through editor and not via script? To make the value stored by string variable to appear when I write variable on text input in Unity's Editor Inspector?

the second problem is; I have Serializable ScriptableObject storing dialogue strings for my NPCS. For example one of them is; public string greeting; and so I fill these string values of ScriptableObject on editor inspector, let's say

 public string greeting;

And it is: "Hello Player.Instance.playerName, it's nice to meet you!" and yes, it's just not working. In game dialogue box, I want it to show "Hello Jack, it's nice to meet you" but it just shows variable as the way it is.

Is there an ideal way to do what I'm trying to do? All helps and suggestions are appreciated!

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mrknztrk · Jan 31 at 10:38 AM

So I found a way to achieve this, however I don't know if it's the ideal way or cleanest way to accomplish it but it works. I'm still open to better suggestions, so please feel free to share your thoughts, it's more than welcome. I use string.Replace to achieve what I'm trying to do. I created an array of string tokens for string, integer variables from script or other things that won't show up properly on dialogue box, like new line "\n". So there are 2 elements in array right now, one for player name and the other for new line. I created two tokens both for player name and for new line "\n". Then I created function to search for tokens each time a dialogue that will be present in game. I don't know if it is ideal way to do it performancewise, whether is it expensive or not; however it seems to work.

 public string [] stringTokens; // 0 <plyrnm>,  1 <nn>
 public string dialogueSpeech;
 public void StringTokenSearcher()
 {
     for(int i = 0; i < stringTokens.Length; i++)
     {
         if (dialogueSpeech.Contains(stringTokens[i]))
         {
             switch (i)
             {
                 case 0:
                     dialogueSpeech=dialogueSpeech.Replace(stringTokens[i],Player.Instance.playerName);
                     break;
                 case 1:
                     dialogueSpeech= dialogueSpeech.Replace(stringTokens[i], "\n");
                     break;
             }
         }
     }
 }










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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

192 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using variable names as seen in the inspector 1 Answer

Accessing scriptable object classes class from other script 1 Answer

How to redraw a texture on a prefab instance when a property in the inspector is changed by the developer? 0 Answers

Storing levels data as json? 0 Answers

Help! with the Message text 0 Answers


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