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
0
Question by RSunity · Feb 03, 2011 at 09:46 PM · javascriptgameobjectvariableguitext

How do I change the text of a GUIText object through another GameObject using a variable?

The title might be a little hard to understand so basically this is what I want to do:

I have a GUIText object and I want to put a script on a GameObject (cube). This script will have a variable like var EnemyName = "";

I want to put that script on that GameObject (cube), so I can set a particular text for the GUIText object through the inspector for the cube. I will be doing this for more than one GameObject.

How do I do this?

Comment
Add comment · Show 1
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 Vinpasso · Feb 03, 2011 at 10:02 PM 0
Share

I have no evidence for this but out of the blue i think you would have to reference the GUIText object and then set the GUIText.text variable to enemy name However way simpler would be to just use OnGUI() and then use a GUI Label inside that

2 Replies

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

Answer by e-bonneville · Feb 03, 2011 at 10:06 PM

Here's an untested JS version of what you could do:

var label : GUIText; var enemyName = "";

function Update() { label.text = enemyName; }

You'd put that script on your cube and assign your GUIText to the variable Label in the Inspector. After that the GUItext will always equal the enemyName variable on the cube.

Hope this helps!

Comment
Add comment · Show 3 · 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 RSunity · Feb 03, 2011 at 10:34 PM 0
Share

It works, thanks!

avatar image e-bonneville · Feb 03, 2011 at 10:37 PM 0
Share

No problem! ;-)

avatar image heaversm · Jul 15, 2011 at 08:28 PM 0
Share

I'm trying to do this, but the script which has access to the variable I need (in the example above it would be enemyName) is a script which is not attached to an object. How would I do it in that case? I need a way to reference the field

avatar image
1

Answer by lCmt · Oct 04, 2013 at 03:26 PM

Hey guys,

I'm doing it in C# and I can't get it right, I'm getting this error all the time:

error CS1955: The member `UnityEngine.GUIText.text' cannot be used as method or delegate

Here's my code

 [System.Serializable]
 public class ViewScrollZoom : MonoBehaviour {
 
 public GUIText debugger;
 
 void Start() {
 
 }
 
 void Update () {
         
    if(Input.touchCount == 1){
       debugger.text("Touching screen now");
     }
 }
 


EDITED

Sorry for being stupid. I was trying to figure it out for at least an hour, and finally saw it in front of my eyes... The good part is that I couldn't find this error referenced anywhere so I'll just leave it here for future intelligent crowd..

It should be debugger.text = "Clicking with mouse left ";

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

2 People are following this question.

avatar image avatar image

Related Questions

How to deactivate something when holding down a key? 1 Answer

how can I display a variable as a GUIText 5 Answers

Access a String array in one script from another script 0 Answers

GameObject variable change for all of the objects 1 Answer

How do I create an array for multiple targets? 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