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
0
Question by gdennis · Nov 19, 2014 at 05:27 PM · guionguipositioning

Relative positioning of speech bubble

I followed the speech bubble tutorial at http://www.41post.com/4545/programming/unity-how-to-create-a-speech-balloon. And i want to put this pointing at the head of my NPC characters when they say something. The solution is working fine however the positioning of the element is definitely not what I want, I tried fiddling here and there with the offsets but i couldnt get it working. Look at the two screenshots I included of how it looks like ingame. The first one is the 'small' view which just doesn't show the text at all (http://imgur.com/TET1xj3). while the second one does show the balloon but as you can see it is way to low (http://imgur.com/VvngEF6)

My code is:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 //tutorial followed at http://www.41post.com/4545/programming/unity-how-to-create-a-speech-balloon
 //Edited to my own needs (appear on collision, positioning, ...)
 
 public class SpeechBubble : MonoBehaviour {
 
     private Transform goTransform;  
     private Vector3 goScreenPos;  
     private Vector3 goViewportPos;  
 
     public static bool bubbleShow { get; set; }
     
     public int bubbleWidth = 300;  
     public int bubbleHeight = 100;  
     
     public float offsetX = 0;  
     public float offsetY = 250;  
     
     private int centerOffsetX;  
     private int centerOffsetY;  
     
     private Material mat;  
     private GUISkin guiSkin;
 
     public string whatToSay { get; set; }
 
     //use this for early initialization  
     void Awake ()  
     {  
         bubbleShow = false;
         mat = (Material)UnityEngine.Resources.Load ("White Unlit", typeof(Material));
         guiSkin = (GUISkin)UnityEngine.Resources.Load("GUISkin", typeof(GUISkin));
         goTransform = this.GetComponent<Transform>();
     }  
 
     void Start()  
     {  
         if (!mat)  
         {  
             Debug.LogError("Please assign a material on the Inspector.");  
             return;  
         }  
 
         if (!guiSkin)  
         {  
             Debug.LogError("Please assign a GUI Skin on the Inspector.");  
             return;  
         }  
         
         centerOffsetX = bubbleWidth/2;  
         centerOffsetY = bubbleHeight/2;  
     }  
     
     //Called once per frame, after the update  
     void LateUpdate()  
     {  
         goScreenPos = Camera.main.WorldToScreenPoint(goTransform.position);   

         goViewportPos.x = goScreenPos.x/(float)Screen.width;  
         goViewportPos.y = goScreenPos.y/(float)Screen.height;  
     }  
     
     //Draw GUIs  
     void OnGUI()  
     {  
         if (bubbleShow) {
 
             GUI.BeginGroup(new Rect(goScreenPos.x-centerOffsetX-offsetX,Screen.height-goScreenPos.y-centerOffsetY-offsetY,bubbleWidth,bubbleHeight));  
             
             GUI.Label(new Rect(0,0,200,100),"",guiSkin.customStyles[0]);  
             
             GUI.Label(new Rect(10,25,190,50),whatToSay,guiSkin.label);  
  
             
             GUI.EndGroup();  
         }
     }  
     
     //Called after camera has finished rendering the scene  
     void OnRenderObject()  
     {  
         if (bubbleShow) {
             GL.PushMatrix ();  
             mat.SetPass (0);  
             GL.LoadOrtho ();  
             GL.Begin (GL.TRIANGLES);  
 
             GL.Color (Color.white);  
 
             GL.Vertex3 (goViewportPos.x, goViewportPos.y + (offsetY / 3) / Screen.height, 0.1f);  
             GL.Vertex3 (goViewportPos.x - (bubbleWidth / 3) / (float)Screen.width, goViewportPos.y + offsetY / Screen.height, 0.1f);  
             GL.Vertex3 (goViewportPos.x - (bubbleWidth / 8) / (float)Screen.width, goViewportPos.y + offsetY / Screen.height, 0.1f);  
 
             GL.End ();  
             GL.PopMatrix ();  
         }
     }  
 
     void OnTriggerEnter(Collider other) {
         bubbleShow = true;
     }
 
     void OnTriggerExit(Collider other) {
         bubbleShow = false;
     }
 }


Does anyone have a solution to this or a better solution to speech bubble generation in general?

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 MrSoad · Nov 19, 2014 at 02:33 PM 0
Share

Yep, not the best place to have the speech bubble co$$anonymous$$g from, lol. You are probably placing it by the players anchor point(His Vector3 position), which will be around his center(rear), you need to offset the y position value of the speech bubble placement in relation to the characters Vector3 position to raise it up higher (y + 1 ish will probably do).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by parasaravasudev · May 19, 2018 at 10:08 AM

Hi Guys, I have seen one more new app in ios, Name : Fotometka Free app for speech text bubbles in ios and app store such a nice app easy to share in social networks

,Hi Guys I have seen one more new app in ios Name : Fotometka Free app for speech text bubbles in ios and app store such a nice app easy to share in social networks

https://itunes.apple.com/us/app/fotometka/id1076869356?mt=8

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity 4.7 - OnGUI prevent click/touch through 0 Answers

why is my GUI script bugging other GUI scripts? 0 Answers

OnGUI button created by a foreach loop 4 Answers

How completly remove GUI.Repaint() calls ? 1 Answer

GUI Placement Question. 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