Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
-1
Question by DeuS · Oct 09, 2013 at 12:02 PM · stringautomaticallyword

Split string, add action to every word

There is a text. Which must be split into words and to create an action to every word, when pressed, plays a sound file, specified for this word.

How to do it automatically? Let's say I know how to split a string into words, and how to add action to every word?

I need to create gameObect according to each word and specify Rect according to a word position, then add script to interact with this Rect? But how to calculate each word position?

And maybe there are another solution?

I add a little more explanation:

I dont know how to do 1) and 2).

 public class Texttext : MonoBehaviour {
     public GUIText guiText;
     public ActionOnClick actionScript;
     // Use this for initialization
     void Start () {
         guiText.text = "Text, text text!\nText? Text!\nText, text text, text...";
         string[] split = guiText.text.Split(new char[] { ' ', ',', '.', ':', '\t', '\n'});
         foreach (string str in split)
             if (str != "")
             {
                 Debug.Log(str);
                 // Create GameObject
                 GameObject go = new GameObject(str);
 
                 // 1) Calculate word position (!!!)
                 Vector3 wordPosition = new Vector3(0, 0, 0);
 
                 // 2) Create Rect according this position (!!!)
                 Rect wordRect = new Rect(wordPosition.x, wordPosition.y, wordWidth,wordHeight);
 
                 // Add action to this gameObject
                 go.AddComponent<ActionOnClick>();
                 go.GetComponent<ActionOnClick>().wordPosition = wordPosition;
                 go.GetComponent<ActionOnClick>().wordRect = wordRect;
             }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

The problem is to automate this: Write text -> Calculate -> Click on Word get a Sound.

And that's what I want to get:

alt text

text.png (4.2 kB)
Comment
Add comment · Show 1
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
avatar image verenion · Oct 09, 2013 at 12:37 PM 0
Share

"HOW DO I CODE?" is basically the question you are asking. String manipulation, iteration and arrays are pretty basic concepts.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Sisso · Oct 09, 2013 at 12:29 PM

split a string into words,

http://msdn.microsoft.com/en-us/library/b873y76a.aspx

create gameObject

http://docs.unity3d.com/Documentation/Manual/InstantiatingPrefabs.html

specify Rect according to a word position

http://docs.unity3d.com/Documentation/ScriptReference/Camera.WorldToScreenPoint.html

how to calculate each word position

http://docs.unity3d.com/Documentation/Manual/GameInterfaceElements.html

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

17 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

Related Questions

int.parse with decimal? 1 Answer

how to display a long string sentence by sentence instead of character by character? 1 Answer

Sending a string via email from Unity? 2 Answers

how can i split a word to individual letters..?? 2 Answers

Number 0 not showing up in GUI.Button 2 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