• 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 Tommy · Oct 31, 2010 at 01:37 PM · gameobjectvariableguitextaccessother

Access guiText from other object.

Hi! Simple question, how do i access a guitext that is attached to a other gameObject than the script. The gameObject name is stored in a variable. Thanks in advance!

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
0

Answer by lhk · Oct 31, 2010 at 01:54 PM

Add a variable to the script that needs to access the guitext. The variable should be public so you can assign the guitext to it via the inspector.

public GUIText referencetotext;

When you have set this variable to the guitext you can modify the guitext from your script by using the referencetotext.

void Start()
{
    referencetotext.Text="Hallo";
}
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 Tommy · Oct 31, 2010 at 03:26 PM 0
Share

Thanks for the answer, sure works! Problem is that im using Javascript, is there something familiar like this in JS? Im not that familiar using C, so i can't convert it myself, since i don't understand C that much. Thanks!

avatar image matthew 2 · Mar 19, 2012 at 12:40 PM 0
Share

basically it is public GUIText referencetotext; function Start () { referencetotext.Text="Hallo"; } in javascript :) LOL Never knew how learning web scripting and windows program$$anonymous$$g actually made sense :P

avatar image
0

Answer by lhk · Oct 31, 2010 at 04:17 PM

In Javascript the script should look like this

var referencetotext : GUIText;
function Start()
{
    referencetotext.Text="Hallo";
}

However I don't have much experience with Javascript so I'm not completely sure.

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 Tommy · Oct 31, 2010 at 04:29 PM 0
Share

Works! Now, i can only change the text that i have choosen, i need to be able to display the text attached to a certain gameObject, depending on wich gameObject is selected. I have the gameObject name stored in a var, i need to access the text attached to that gameObject.

avatar image
2

Answer by lhk · Nov 01, 2010 at 08:00 AM

Try this

  1. declare a variable for your object. var object : GameObject;
  2. declare a variable for the GUIText. var text : GUIText;
  3. Find the object you need by using GameObject.Find("thename"). object=GameObject.Find("name");
  4. Access the GUIText component of this GameObject. You can use GameObject.GetComponent(). text=object.GetComponent(GUIText);
  5. Now you can change or use the text of this GameObject. var content=text.Text; text.Text="Hello";
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 Zinger · Dec 15, 2012 at 05:02 PM 0
Share

This is what I needed.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

how can I display a variable as a GUIText 5 Answers

How to access gameObject variable script 2 Answers

Get GameObject name from other object. 2 Answers

Access variable from script on other gameobject. 1 Answer

SOLVED - Accessing a C# script value from another GameObject's JavaScript 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