Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by xxluky · Aug 01, 2015 at 09:31 AM · namespaceaccessing scripts

How to access public variable in namespace

Hello, I am working with Platformer Character 2D from the Standard Assets. In project pane I created a new script with public static variable bool. I want to access this public bool which is in a public class in the script of the 2D character which is in a namespace UnityStandardAssets._2D.

In the player script when I type the name of my public class it just do not show up... Any solutions?

Example: My public class:

public class Bumper : MonoBehaviour { public static bool bumper; }

Script of the 2D character from the standard assets where I would like to access a variable bumper:

namespace UnityStandardAssets._2D { public class PlatformerCharacter2D : MonoBehaviour { // here I want to acces my public static bool bumper. }

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 xxluky · Aug 01, 2015 at 09:37 AM 0
Share

Example: $$anonymous$$y public class:

 public class Bumper : $$anonymous$$onoBehaviour
 {
    public static bool bumper;
 }

Script of the 2D character from the standard assets where I would like to access a variable bumper:

 namespace UnityStandardAssets._2D
 {
     public class PlatformerCharacter2D : $$anonymous$$onoBehaviour
     {
       // here I want to acces my public static bool bumper.
     }

3 Replies

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

Answer by Bunny83 · Aug 01, 2015 at 06:00 PM

I guess you have the PlatformerCharacter2D script either inside "Standard Assets" or "Plugins" but your "Bumper" script outside. Things in those folders belong to a different compilation group. They are compiled before your actual scripts. Things in those folders must not have any dependencies to classes outside those folders. If PlatformerCharacter2D class needs access to your Bumper script, either move your Bumper script into Standard Assets as well or move your PlatformerCharacter2D class out of the Standard Assets folder.

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 xxluky · Aug 02, 2015 at 11:51 AM 0
Share

Yeah, it is as you say. I put my script into Standard Assets folder and now that script is visible. How come? There must be any other way. I want to have my staff nice and neat. Is it possible to access my scripts within Standard Assets scipts?

avatar image Bonfire-Boy · Aug 02, 2015 at 01:38 PM 1
Share

I may be missing something but I don't understand why you are editing Standard Assets at all. Try leaving that folder alone, and putting all your own code elsewhere.

avatar image
1

Answer by Hexer · Aug 01, 2015 at 09:33 AM

method : Scriptname.variablename.

if the name of the script is X and the variable in that script that you want to access is y, you refer it in another script as X.y

 NameOfScript.bumper

If you are still confused here's a link to Unity Learn tutorial about Statics : https://unity3d.com/learn/tutorials/modules/intermediate/scripting/statics

And a link to namespace https://unity3d.com/learn/tutorials/modules/intermediate/scripting/namespaces?playlist=17117

Comment
Add comment · Show 4 · 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 xxluky · Aug 01, 2015 at 11:25 AM 0
Share

Yeah, I get it. But in the namespace the name of my script is not visible.

I still don't know how to reference my variable bumper. I don't know what namespace it is and which using to add. Can anybody tell me according to my example above how to access the variable bumper in namespace UnityStandardAssets._2D ??

avatar image Hexer · Aug 01, 2015 at 11:39 AM 0
Share

bool bumper = Bumper.bumper;

avatar image xxluky · Aug 01, 2015 at 11:47 AM 0
Share

bool bumper = Bumper.bumper;

No, the name of the script "Bumper" is not visible in the namespace. It is in a different folder of o project - does it matter?

avatar image xxluky · Aug 01, 2015 at 04:24 PM 0
Share

Any suggestions?

avatar image
0

Answer by tpainton · Dec 22, 2016 at 07:38 PM

You need to include the name space. So any script that accesses the target script needs

 using UnityStandardAssets._2D;
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

25 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 avatar image avatar image

Related Questions

error CS0246: The type or namespace name `rect' could not be found. 1 Answer

error CS0246: The type or namespace name `List' could not be found. 1 Answer

Namespace Functions not being recognized 0 Answers

Can't access another script, think it may be due to namespace/public class ? 1 Answer

Inspector references and scripts with the same name 0 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