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 Proximal-Pyro · Mar 08, 2013 at 08:46 AM · staticvar

Static variables explanation.

Hey.

I have a question. I'm working on a rpg game and I'm using static var to access varibles from other scripts. It works good exept for one thing. The static varibles doesn't show up in the inspector window. Is this a bug or a feature in unity? And what other ways are there to access varibles from other scripts? I don't understand this:

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

Thanks. //Proximal-Pyro

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Chronos-L · Mar 08, 2013 at 09:20 AM

Which part of it you do not understand? Please don't say the whole thing.

public static variables are not shown in the inspector because static variables belong to the class itself, not the object/instance of the class.

Non-`static` variables in the other hand, belongs to the object/instance of the class. When a gameObject is attached with a script, it becomes the object/instance of the class of the script, and hence, the public non-`static` variables will then be exposed in the inspector.

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 Proximal-Pyro · Mar 08, 2013 at 09:24 AM 0
Share

I don't understand how to access varibles. That page only explains how to access functions, right?

//Proximal-Pyro

avatar image Chronos-L · Mar 08, 2013 at 09:33 AM 0
Share

If your variable is declared as public, you can access them like any public functions. The page is mainly about accessing other gameObject in the scene and how to manipulate these gameObject's component. It is not just about how to access functions.

The 3rd script in that page

 // Set foo DoSomething on the target variable assigned in the inspector.
 
 var target : OtherScript;
 
 function Update () {
 
     // Public variable
     target.foo = 2;
 
     // Public function
     target.DoSomething("Hello");
 }
avatar image Khada · Mar 10, 2013 at 02:09 AM 0
Share

This should be marked as the correct answer.

avatar image
0

Answer by whydoidoit · Mar 08, 2013 at 09:19 AM

Variables which are static are not related to the specific object and so do not show up in the inspector. Using Static may not be the best method (see GetComponent articles on Unity Gems) but if you do decide on that route - you can create a script that has normal variables which it puts into the statics on Awake - then you have a way of defining them in the inspector.

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

13 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

Related Questions

Multiple Cars not working 1 Answer

Static variables 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Native visual scripting? 0 Answers

Pain in the ass 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