• 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
Question by Adam Bruns · Mar 04, 2010 at 12:28 AM · variablestaticjavascript-specific

Access a static var from different named scripts?

(t$$anonymous$$s is for testing purposes, and hopes to be adapted to my real game later)


I want to make multiple buttons on the GUI, (lets just say 3 buttons), When you click on the first button, the number1 script is activated the rest are deactivated, when you click on 2, 2 is activated rest deactivated, and same for 3 (the 3 scripts contain static vars for a weapons minimum and maximum damage). now i know how to do that, but i need help with t$$anonymous$$s, i want my characters Attack script to be able to figure out w$$anonymous$$ch script is activated, grab its static var, and place it in a variable inside of a function. I already have everyt$$anonymous$$ng setup IF i put the variables inside the function directly, i just need help to make it grab them from the other scripts
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Ashkan_gc · Mar 04, 2010 at 07:34 AM

to use static variables you just need to use classname.staticvariablename = xxx but your questions is not as clear as it should be.

Comment

People who like this

0 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 Adam Bruns · Mar 05, 2010 at 02:36 AM 0
Share

ok i have script A script B and script C on an empty game object, if A is activated, B and C are deactivated. if B is activated A and C are deactivated. so on so forth. I want my other script, named Attack, to be able to find out which script is activated (A B or C) and grab its static var.

avatar image Joshua Falkner · Apr 01, 2010 at 04:37 PM 0
Share

Sounds like you're going to need to create a static boolean var on each script and set it to true or false when it's activated. Then your character can check to see which script is true.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

from which script was it? 2 Answers

Static variables 1 Answer

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

Finding the length of a string 2 Answers

variable = true 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