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 /
This question was closed Mar 19, 2015 at 07:43 PM by fafase for the following reason:

Duplicate Question

avatar image
0
Question by Xeong-Hu · Mar 19, 2015 at 06:49 AM · variableclassmonobehaviour

How may i get a variable from another script onto my wanted Script?

Hello Happy Helpers!

I totally would like to know how I could get a variable from one of my scripts and use it in another

I'm using C# Btw!

Well I know how to get a function from another script but I just cant get the knack to getting a variable from another script.

If anyone can help I'd Appreciate it! Yeah@!

Comment
Add comment · Show 3
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 Eluate · Mar 19, 2015 at 07:05 AM 0
Share

Duplicate of: http://answers.unity3d.com/questions/42843/referencing-non-static-variables-from-another-scri.html

avatar image Xeong-Hu · Mar 19, 2015 at 03:55 PM 0
Share

I'm sorry about that Static.

I searched up GetComponent solutions in the searches and I didn't find that question.

Guess I was searching wrong then.

$$anonymous$$y bad!

avatar image fafase · Mar 19, 2015 at 07:43 PM 0
Share

Saying you search is an euphemism. There are hundreds of threads for that matter and tens of detailed ones.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by marijnroukens · Mar 19, 2015 at 08:57 AM

First get the object where the script you are trying to acces is attached to, for example I will use Player as the object:

 var Player = GameObject.Find ("Player"); 

Then get the script that you need, for example the script attached to the player is healthScript. Put this Before you are loading the variable:

 healthScript healthScript = Player.GetComponent<healthScript> ();

Then to acces the variable, for example my variable will be playerHealth:

 healthScript.playerHealth = 10;

Now the health in healthScript is set to 10!

Good luck with it!

EDIT: I don't know if this is the best way, but as a student this is the only way I am familiar with. Just trying to help!

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 Xeong-Hu · Mar 19, 2015 at 07:39 PM 0
Share

Thanks for replying I'm still working on it, but now I'm curious.

When you said as a Student. You mean Unity3d Gives Classes to those who want to learn the ways of Unity?

If so is it free classes? Is it online? I'm so curious now.

avatar image Xeong-Hu · Mar 19, 2015 at 08:18 PM 0
Share

Update

Everythings working Crystal Clear, thanks for the tip.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

How transform Variable is accessed in Scripts ? 2 Answers

script needs to derive from monobehaviour 1 Answer

Monobehavior class variable become null after assigning value when instantiated 1 Answer

Parent Class variables in Child Class's Inspector (C#) 0 Answers

InvokeRepeating inside of a class 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