- Home /
The question is answered, right answer was accepted
Instantiate a GameObject at a position specific to an element that was found in a text
Hello! I am currently trying to create a chat using Unity. I am trying to instantiate emoticons at the position that the emoticon symbol was found but I am having to luck as of yet. I am correctly identifying the emoticons but I cannot instantiate them at the position the emoticon symbols were found. Please help me! Thank you!
 foreach (string item in EmojiStringList)
 {                  
     if (usr.GetComponentInChildren<Text>().text.Contains(item))
     {
         switch (item)
         {
             case "^_^":
             {
                 usr.GetComponentInChildren<Text>().text.Replace(item, string.Empty);
                 GameObject emo = Instantiate(emoji[0], position, Quaternion.identity) as GameObject;
                 emo.transform.SetParent(usr.transform, false);
                 break;
             }
         }
     }
 }
I have not tried it yet. But you try to instantiate emoticon at the end of 'Text' component.
For example: If user inputs - " Wassup RedDevil ^_^".
- Delete ^_^ 
- Text left "Wassup RedDevil". 
- Find the position of '.' after string. And instantitae you emote their. 
- Finding the position of dot will depend on you text anchors and position. 
- If user wants to continue after message. For example "Wassup RedDevil ^_^ Got your answer yet?" 
- you instantitae another Text object starting from the right of emote. 
- All this can be easy if there is a method to find position of words inside TExt object. 
well you told me what i already know... I don't need to find the position of "." because i already am searching for the position of "item". I already know the Y and Z I want the emoticon to be instantiated ... the problem is I have no idea how to find the X relative to "item" .
Answer by Rostam24 · Sep 27, 2015 at 02:38 PM
I think you can use quad inside of rich text for this. See also the documentation for rich text: http://docs.unity3d.com/Manual/StyledText.html
Follow this Question
Related Questions
Creating instance of GameObject(Holding component) at same location as object that holds the script 1 Answer
Keep instantiated GameObject's position while parenting it to another GameObject 3 Answers
How do I instantiate same tag/name GameObjects with an array 1 Answer
Adjacent Placement of Objects according to varying height 0 Answers
Change default sprite position when dragged into Hierarchy 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                