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 jjennings1990 · May 07, 2013 at 12:15 AM · gameobjecttext

Ways to break up a text label into separate game objects?

Hi guys so I am programming something that is going to function more like an app than a game and maintains certain functionalities similar to instagram. Right now my current challenge is taking a text label with text and essentially dissecting it into multiple game objects that are then pressable as buttons. it is supposed to act like hashtags and handles on instagram . So within the text labels giving certain texts the ability to be pressed.

The ability to divide a text game object seems next to impossible , but creating a mask or a duplicate text label with the pressable functionality may work . are there any methods you would recommend ?

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

Answer by robertbu · May 07, 2013 at 03:41 AM

I have a couple of ideas. Since I've never done this for "real," I cannot make a recommendation.

1) You could make invisible GUI buttons. Place normal buttons over all the text you want to be hot. Then you can define your own GUIStyle leaving out a texture for the 'Normal' state of the buttons. This solution has the added benefit that you can specify a texture 'Active' texture...quarter opacity perhaps...so the user gets a flash of a texture when the button is pressed as feedback.

2) Your mask idea could be implement as a GUI.DrawTexture and you could sample the color of the texture at the mouse cursor as feedback about the button. I played a bit with this idea:

 public class DetectColor : MonoBehaviour {

     public Texture2D tex;
     private Rect rect; 
     
     void Start() {
         rect = new Rect(100f, 100f, tex.width, tex.height);
     }
     
     void OnGUI () {
         Event e = Event.current;
         
         if (e.type == EventType.mouseDown) {
             if (rect.Contains (e.mousePosition)) {
                 int x = (int)(e.mousePosition.x - rect.x);
                 int y = tex.height - (int)(e.mousePosition.y - rect.y);
                 Color color = tex.GetPixel(x, y);
                 Debug.Log ("x-y ("+x+"-"+y+" color="+color);
             }
         }
     GUI.DrawTexture (rect, tex);
     }
 }

Note with this solution the opacity had to be non-zero for GetPixel to return correct values. Even the lightest value in the alpha channel and it worked.

Comment
Add comment · Show 1 · 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
avatar image jjennings1990 · May 07, 2013 at 07:21 PM 0
Share

That's Definitely Helpful Rober the only issue is the buttons I make are going to be based on user input such as #Unity @workingonStuff . I would have to position the button immediately over the text that is " marked" so to speak . I thought about writing an algorithm that too in the character size of text , looked at the combined length of a string and somehow positioned the buttons within the ball park of the texts in 3D space but that is going to be extremely difficult and it's a situation where there isn't much concrete within the project so all of those values are subject to change or be changed based on my clients decision.

I do appreciate the idea though , I am asking more for the brainstor$$anonymous$$g effect as it is because I am definitely going to have to explore solutions a bit above my own current understanding of string manipulation and interacting with text labels

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

12 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

Related Questions

Using a lot of calls and if else statement, is there a better way to do this? 1 Answer

Access specific Text among multiple children 0 Answers

How to display text on a gamebject? 3 Answers

Load a GameObject that is outside of script and set it active at the same time 1 Answer

I can't pause my game? How to make a pause menu in C# for SPace Shooter type Game? 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