Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by Eldore · Apr 08, 2016 at 09:53 AM · guitextbox

How to add text to a box ?

Hello everybody.

I have created a GUIBox, and I want it to display text when I ask for it. For example, when I press the button "Attack", a text appears in the box : "You attacked". The box will always be present.

I don't know if it's possible ?

Thanks for your answers and sorry for bad english, it's not my first language.

EDIT : this video help me a lot : https://www.youtube.com/watch?v=wlY5sRewfVQ

PLUS if it's possible, I want to conserve all the text in screen, not just 1 line, but for the moment I don't know how to do.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Pnvanol · Apr 08, 2016 at 10:28 AM

Gameobject ui text, to add the text Then you want to create a script in the text component Unityengine.Ui at the top of it Creat a public text textInsideBox
Drag the text element to the empty text box on the inspector. Then you can change textInsideBox from inside the script anytime you want

Comment
Add comment · Show 13 · 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 Eldore · Apr 08, 2016 at 10:43 AM 0
Share

Thank you for your answer @Ponoveave. But I don't understand what you means by "gameobject ui text" ?

avatar image Pnvanol Eldore · Apr 08, 2016 at 10:45 AM 1
Share

$$anonymous$$enu at the top called gameobject

avatar image Eldore Pnvanol · Apr 08, 2016 at 10:58 AM 0
Share

Ooooh O$$anonymous$$ !! Thank you !

So I create the UI > Text, and a script which contains : public Text textInsideBox;

How can I change the text in other script ??

Sorry, I'm a real noob here...

Show more comments
Show more comments
avatar image Pnvanol Eldore · Apr 08, 2016 at 02:00 PM 0
Share

Ok to add lines you could try to do textInsideBox.text =textInsideBox.text+"anytextyouwanttoadd";

avatar image Eldore Pnvanol · Apr 08, 2016 at 02:19 PM 0
Share

That works but all the text are stuck like this : "you attackyou attackyou attack", and if I use \n the first line just dissapear..

Show more comments
avatar image zeantblaze · Apr 08, 2016 at 11:27 AM 1
Share

Well, like Ponoveave answer. Use the new UI. You can attach a script to detect your input (in your case the attack button) in the text object you create.

avatar image
0

Answer by Dank_Mushies · Apr 23, 2016 at 03:08 AM

Try this simple example:

 string customText;
 onGUI()
 {
 GUI.Rect(new Rect(TextRect),""+customText);
 
 if(GUI.Button(new Rect(buttonRect),"Attack Button")
 {
 customText = "Add your text here";
 }
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

TextUI text changes size if resolution changes 1 Answer

Using Japanese in my game 1 Answer

TextMeshPro Set Alpha Color 0 Answers

How to draw text in a non-rectangular area 0 Answers

Stop Text object moving with player 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