• 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
Question by DRCUnity · Feb 22, 2016 at 01:17 PM · textwriting to text

How to write and place text via runtime?

Hello,

I am trying to write text in game via the player but unfortunately i didn't find any toturial explaining how to do this and didn't come across any explaination.. maybe you guys can help me out. So this is what i mean:

In runtime, the player goes to a wall and can pop out a menu (i already got this menu) the player clicks on a button called "write text" and this is where it gets tricky for me:

the player can write something in maybe a inputfield (can be anything) and get te value of the input field to create text(3D text or whatever is possible).

thanks in advance.

Comment

People who like this

0 Show 5
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 itsharshdeep · Feb 22, 2016 at 01:31 PM 0
Share

Hi, As you explain your problem ..can you please describe that in this whta problem you are facing? .. If you donot know how to do this the. Then Following is the way ( so far I understand ) 1. After taking the click from the user you may open the input field. 2. Then what ever the user input in the input field you can take that string from that and display the same in the 'text mesh' ( which may already present there but invisible) or 'UI text' .. if the game is in 3D the you can use world space canvas ( that will help you to place the tezt field anywhere in 3D world) .. Sorry if I misunderstood

avatar image DRCUnity itsharshdeep · Feb 22, 2016 at 03:53 PM 0
Share

Thanks for the fast reaction, yes you understand it well.

1.when i press the button on the menu i want the "screen space canvas" to appear with the inputfield

  1. then when i put in some text in the inputfield, i want to be able to drag and place it somewhere.

I think by "text mesh" you meant 3D text? if so than yes, if it is possible it can be normal text also.

in short : i want to place (3D) text with the value of the input field.

regards

avatar image itsharshdeep DRCUnity · Feb 23, 2016 at 04:25 AM 0
Share

Yes you are right .. Test mesh means 3D text :)

I think all things are clear now .. Please correct me if I'm not .

Thanks

Show more comments
avatar image rajavamsidhar_gvs · Feb 23, 2016 at 11:17 AM 0
Share

if i understand your question ,,,Take one textmesh(3d).then click button write text to enables gui textfield..link that gui.textfield content string to textmesh.it will give.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by rajavamsidhar_gvs · Feb 23, 2016 at 11:21 AM

try it.not tested.attatch script to your player.drop your Text ui into txt variable,drop your inputfield object into inputfield.disable your button,and play.you will get a button on left top corner.click it. text field will enable then type.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 public class PlaceText: MonoBehaviour
 {
     public bool enableText;
     public GameObject txt,inputfield;
 void Start()
 {
 inputfield.setActive(false);
 }
     
     void OnGUI()
     {
     if(GUILayout.Button("write text"))
     {
     enableText=!enalbleText;//for enable disable text field
     }
     if(enableText)
     {
 inputfield.setActive(true);
 
  InputField inputFieldCo = inputfield.GetComponent<InputField>();
     Debug.Log(inputFieldCo.text);
    txt.GetComponent<Text>().text=inputFieldCo.text;
     }

else{ inputfield.setActive(false);

} } }

Comment

People who like this

0 Show 6 · 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 DRCUnity · Feb 24, 2016 at 02:45 PM 0
Share

Can you tell me how to set up my layout what component i must add and set name to and in wich component you think the scripts belongs to cause i cant figure it out. sorry i am still new in unity.

the img is how i set my layout in unity without the menu just button for a test.

ialt text

test-set-text.jpg (88.1 kB)
avatar image rajavamsidhar_gvs DRCUnity · Feb 26, 2016 at 07:33 AM 0
Share

i updated my answer.actually my precess is not right way.but you will get out put.let me know results.i'll give total information in a proper way.

avatar image DRCUnity rajavamsidhar_gvs · Feb 26, 2016 at 03:14 PM 0
Share

I have tested it and change the code cause it gave me some errors and now the code is working.

I have two button but i only created one. i created (default button "write text") and the other button i see only when i Run the game and its thalt textat button that enables the inputfield and the texfield not my default button even tho i have put the script in my default button. when i click the other button not the default button of mine but the other on the left corner. it makes the inputfield and texfield if i click second time it doesn't disable it or make it unvisible.

what i only need is to place the textfield somewhere in the world and let it stay there while i am doing something else.

Thank you for helping me so far i really appreciate your time.

vissible-inputfield-texfield.jpg (316.6 kB)
test-set-text.jpg (49.7 kB)
Show more comments
Show more comments
avatar image

Answer by MountDoomTeam · Feb 26, 2016 at 08:05 AM

Some basic options can be:

find a way to input text that is completely controlled by script... you need either a code that can detect all key presses and tell you which was returned, which you can activate when you sense it is time to type something... and then convert the string into 2d or 3d text... so search questions on how to detect any key presses...

you can use textfield... activate deactivate it so that it appears and dissapears on screen, you can have it any size, it's just a GUI widget which you input text into... you can probably put it in the middle so the guy can start typing, and move it away from screen while he is typing if you want, and then display the string within it as 2d or 3d text of your choosing...

http://docs.unity3d.com/ScriptReference/GUI.TextField.html

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Writing on text file in an Android Build 1 Answer

How to add my text reveal script to an asset menu item (text adventure unity tut) 0 Answers

How to add extra text to GUI.Box? 1 Answer

How do you display changing stats on a "Card"? 1 Answer

move position of gui texture 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