• 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 yoelleoy · Jan 24, 2016 at 04:10 PM · scripting problemerrorjava

Text is not a member of UnityEngine.Component error

Im trying to make aScoreboard but I am getting this error

 var gui : GameObject;
 static var CurrentScore: int;
 
 function Update ()  
 {
     gui.GetComponent("GUIText").text = "Score: " + CurrentScore;
 }
Comment
Add comment · Show 2
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 Fattie · Jan 24, 2016 at 04:10 PM 0
Share

are you usng unity's "old" gui? you cannot. use the new "UI" system (it is very easy)

avatar image Fattie · Jan 24, 2016 at 09:25 PM 0
Share

NEVER, EVER use javascript, you $$anonymous$$UST change to c#

Unity are getting rid of javascript soon (see their blog)

Note - c# is actually easier anyway.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Fattie · Jan 24, 2016 at 04:09 PM

Surely the component type name would be Text

To find doco on the UI (some people still say "new" UI, but it is years old now)

https://unity3d.com/learn/tutorials/topics/user-interface-ui

surprisingly the Unity doco is quite good on this topic.

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 yoelleoy · Jan 24, 2016 at 04:24 PM 0
Share

Ok it was Text I was trying to follow what there is online, but there is a LOT of stuff about the old gui and I can't find any good guide about the new gui :(

avatar image Fattie · Jan 24, 2016 at 04:53 PM 0
Share

Hi yoelleoy. As a new user it's critical you

TIC$$anonymous$$

a useful answer. Green symbol on your left.

It's how you get points, so that your questions will not be moderated in the future. Please do this. Cheers!

avatar image
1

Answer by phil_me_up · Jan 24, 2016 at 07:35 PM

Gah, had written a nice reply then realised you were using Javascript rather than C#. Makes the answer somewhat simpler:

 gui.GetComponent(GUIText).text = "Score: " + CurrentScore;

Basically, remove the " so you just pass in the type of object you're expecting to get a result about, not a string.

Personally I never use Javascript so that might not work, in which care you might need something like

 function Update()
 {
 var myGuiText : GUIText;
 myGuiText = gui.GetComponent(GUIText);
 myGuiText.text = "Whatever";
 }

That's not really a very elegant answer as there are no checks to make sure that myGuiText is actually an object (might return null if GUIText doesn't exist as a component on your object) and calling GetComponent every frame is slow.

Personally, I'd recommend looking at switching to C#. It's a little more intimidating if you're getting started but you'll be better off in the long run (most examples etc focus on C# too).

As Fattie said too, the newer UI system is the way to go. It's far more efficient to build and execute and I imagine there are plenty of samples around.

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 Fattie · Jan 24, 2016 at 09:26 PM 0
Share

it looks like the OP is using new UI, and meant to type "Text"

it's absurd Unity have not removed the old gui shit, they need to

(*) did not notice the OP is using javascript, yah that has to go.

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

6 People are following this question.

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

Related Questions

error CS1525: Unexpected symbol `nextState' / mecanim / anystate problem 0 Answers

Collisions arn't working properly 0 Answers

IL2CPP does not support marshaling delegates that point to instance methods to native code. 1 Answer

Error building Player: CommandInvokationFailure 0 Answers

Getting an error while trying to get scene name 1 Answer


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