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 douglasg14b · May 08, 2015 at 06:49 AM · uitext

Make a UI text box with selectable text?

I'm trying to make a simple chat system for our games lobby, however I am unable to figure out how to make text in the text box selectable. So that users can highlight it and copy it if they want, like you should be able to with normal text. I'm using the Unity UI for this.

Any suggestions?

Comment
Add comment · Show 3
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 anniyan137 · May 08, 2015 at 07:03 AM 0
Share

Give a bit more detail. What are you using? Are you using Unity GUI or some other 3rd party tool like NGUI?

avatar image zeppike · May 08, 2015 at 07:27 AM 0
Share

It would be also beneficial to know what platform are you a$$anonymous$$g for.

avatar image douglasg14b · May 08, 2015 at 03:35 PM 0
Share

I'm using the Unity UI. Not NGUI, not OnGUI.

I'm ai$$anonymous$$g for Windows/$$anonymous$$ac/Linux platforms

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jott · Feb 15, 2016 at 05:08 AM

Not exactly a timely response but nevertheless,

I've come across the same problem, and put together this little script. Just attach to a gameobject with an inputfield and set the inputfields text to whatever it is you want to be selectable but not editable. Currently doesn't have the ability to change through code, but that would be simple enough to implement I think.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(InputField))]
 public class SelectableText : MonoBehaviour {
 
     string text;
 
     InputField field;
 
     // Use this for initialization
     void Start () {
         field = GetComponent<InputField>();
         text = field.text;
         field.onValueChanged.AddListener(s => field.text = text);
     }
 }

Basically you just reset the input field to your initial value whenever the user tries to change it.

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
avatar image
0

Answer by TheRichardGamer · May 24, 2016 at 03:45 PM

Well, there's actually an option on the InputField that says "Read Only" which allows the user to select the field and copy its contents but it does not allow the user to edit the field.

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
avatar image
0

Answer by OctoMan · May 08, 2015 at 04:00 PM

Just use the InputField in the new UI System. It has everything you need. If you need to code something inside dont forget to use the namespace UnityEngine.UI

Comment
Add comment · Show 5 · 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 douglasg14b · May 08, 2015 at 04:22 PM 0
Share

I was fiddling with the input field, how do I make it so the text is non-editable? I want to be able to select and highlight it, but not edit it in any way.

avatar image OctoMan · May 08, 2015 at 07:06 PM 0
Share

inputfield.enabled = false;

you may want to set it depending on inputtypes to what ever you need. Like if there is mouseinput set it to enabled. If there is keyboard input set it to false. $$anonymous$$ight work, never tested!

avatar image douglasg14b · May 08, 2015 at 07:15 PM 0
Share

Sadly disabling the input field also disables the ability to highlight, and I'm unable to selectively disable specific input types for the input field only (unless someone knows how).

avatar image OctoMan · May 08, 2015 at 07:39 PM 0
Share

http://docs.unity3d.com/460/Documentation/ScriptReference/UI.InputField.html

It has alot possibilitys, like select and so on. you might want to take a closer look. When i have time i'll look deeper into it.

avatar image douglasg14b · May 08, 2015 at 07:45 PM 0
Share

Trust me, I've been pouring over it since 8 in the morning (nearly 5 hours ago) trying to figure it out. Pretty sure I have almost every unity answer question and forum post question for the input field open at this point.

I'll keep searching, thanks.

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

23 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

Related Questions

Make UI always center the panel 1 Answer

How can I create an NPC Dialogue with UI Text? 1 Answer

Maintaining Text Size Ratio With Screen 0 Answers

Can't change UGUI text color after assign material ? 0 Answers

Preference settings for commonly used items? 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