Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
9
Question by Team_26 · Dec 06, 2014 at 03:52 PM · c#uitextinterfacetype

How to edit UI Text from script

Hi! I've got a problem with editing new UI Text from script. I attached this (part of) script to my UI Text gameObject:

 Text score;
 
 void Start()
 {
     score = GetComponent<Text>();
     score.text += objects.Player_Score;
 }

and I received this compilation fail:

Assets/Scripts/Menu/gameOverScoreDisplay.cs(6,9): error CS0246: The type or namespace name `Text' could not be found. Are you missing a using directive or an assembly reference?

What should I do to use 'Text' type in my scripts? I saw the same part of script in the official Unity video (LINK)... Yes, I've got the newest Unity update (4.6).

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

3 Replies

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

Answer by Deadcow_ · Dec 06, 2014 at 04:36 PM

You need to put reference to namespace, where new UI classes contains:

 using UnityEngine.UI;


Or you also can refer to this type as

 UnityEngine.UI.Text score;

and

 score = GetComponent<UnityEngine.UI.Text>();
Comment
Add comment · Show 2 · 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 Team_26 · Dec 06, 2014 at 04:51 PM 0
Share

Thank you.

avatar image MuradD · Mar 02, 2016 at 02:37 PM 0
Share

can you please help me with this in JS ? am new and not enough tutorials about this.

avatar image
3

Answer by dikabeast · Dec 06, 2014 at 07:08 PM

Maybe you forget adding using UI

 using UnityEngine.UI;

About editing text in UI from script you can see here : http://answers.unity3d.com/questions/795069/46-ui-accessing-text-in-image-inside-canvas-via-c.html

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
1

Answer by yoppuyoppu · Aug 08, 2017 at 08:44 PM

If you're having trouble using JS, try the following:

 // at the top of your code where you declare variables
 var score: UnityEngine.UI.Text;

 // no need to do anything inside Start() unless you would like to set an initial value
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

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

Related Questions

Maintaining Text Size Ratio With Screen 0 Answers

C# Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable 2 Answers

if statement not working for user input 0 Answers

Remove the & at the end of concatenated string 0 Answers

Unity UI: Text Adventure 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