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 gentleben · Feb 17, 2012 at 02:22 AM · componentaccessattached

Access to variables from other script objects

Hi I just want to change and display some variables in my player class.

Here is my player class:

 public class SpielerController : MonoBehaviour {
 
 public int SpielerPunktzahl;
 public string SpielerName;
 
 // Use this for initialization
 void Start () {
     this.SpielerPunktzahl = 24;
 }
 
 // Update is called once per frame
 void Update () {
 
 }

}

The GameObject is called "Player1" where this script is attached.

Now I'm trying to get access to these two variables from another GameObjact called "GameGUI". How can i get access from within the script attached to the GameGUI object?

Would be nice if you could help me to solve this problem. I have searched a lot and tried a lot examples from the internet, but nothing worked.

Thaks a lot

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
1

Answer by Esa · Feb 17, 2012 at 06:16 AM

Unity Script reference is your friend: Accessing Other Game Objects.

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 V4mpy · Oct 18, 2013 at 01:58 PM 0
Share

This link does not work anymore. Accessing Other Game Objects.

avatar image Jamora · Oct 18, 2013 at 03:09 PM 0
Share

Here's a very good answer on accessing variables from other GameObjects

avatar image
0

Answer by Dejan1 · May 09, 2013 at 11:49 PM

Just make - public static int SpielerPunktzahl; and you can directly acces and change this variable in another script directly typing the originalscriptname.SpielerPunktzahl=somenumber;

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 allenziff · Dec 05, 2012 at 08:14 PM

type this in the top:

 public static SpielerController instance;

then in the void Start() type in:

 instance = this;

then on the other script type in were needed:

 SpielerController.instance.yourstuff = 12/false/whatever;
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

10 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

Related Questions

Can I access components scripts? 3 Answers

Add material component to object script-wise 4 Answers

A node in a childnode? 1 Answer

Painted Tree's Script Component 1 Answer

Unity crashes when accessing a function of a script from another script 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