Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 AtlasS · Nov 29, 2011 at 11:21 PM · static variable

Editting a static variable?

ok, so to cut straight to the chase; I have 3 scripts. Script A is just a list of variables, Script B is a modified FPS walker script, and script c is a variable altering script. Script A's variables are static so that Script C can access them to change its own variables Script C's Variables are static so script B can access them. Problem: Script B IS accessing script C's variables, but they stay the basic numbers I defined, which means C isn't editting those variables. a snippet of C is to follow

 static var normSpeed = 6.0;    
 static var sprintSpeed = 10.0;    
 static var aimSpeed = 2.0;    
 static var sprintDuration = 15;    
 static var gravity = 20;    
 static var penetrateVal = 1;    
 static var standardSpread = .4;    
     
 function  Start () {}    
       
 function update () {}    
     
     
 function olympian() {    
         Trainer = gameObject.GetComponent("TrainMana");    
         
         if(Trainer.olympian < 2) {    
             sprintDuration = 45;    
             }    
             else if(Trainer.olympian < 3) {    
                 normSpeed = 7.5;    
                 sprintSpeed = 12.5;    
                 aimSpeed = 2.5;    
                 }    
             else if(Trainer.olympian < 4) {    
                 normSpeed = 9.0;    
                 sprintSpeed = 15.0;    
                 aimSpeed = 3;     
                 }    
             else if(Trainer.olympian < 5) {    
                 normSpeed = 10.5;    
                 sprintSpeed = 17.5;    
                 aimSpeed = 3.5;    
                 }    
             else if(Trainer.olympian > 5) {    
                 normSpeed = 12.0;    
                 sprintSpeed = 20.0;    
                 aimSpeed = 5.0;    
             }    
 }
Comment
Add comment · Show 2
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 ptdnet · Nov 30, 2011 at 03:00 AM 0
Share

Where are all of these variables (normSpeed etc) declared?

avatar image AtlasS · Nov 30, 2011 at 03:27 AM 0
Share

Updated to show from top down to the bottom of the Olympian function

1 Reply

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

Answer by Eric5h5 · Nov 30, 2011 at 04:28 AM

There's no reason for those variables to be static. Just make them normal public non-static variables. The purpose of static variables isn't "so other scripts can access them" (that's what public variables are for); rather, a static variable means there is only one instance of it (and this is independent from its public/private state). Read this: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

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 AtlasS · Nov 30, 2011 at 05:08 AM 0
Share

Thank you, after your post I did some fiddling and now everything works just fine. I appreciate your help

avatar image phyzxengr · Jul 05, 2020 at 04:01 AM 0
Share

But in order to access the 'class.method' from another script the class or method has to be static. Otherwise the script has to instantiated in the calling script. Cant have it both ways. I want to use the class.method() way and am battling this complexity that is beyond all understanding.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using raycast - Why can't I get a variable on the object I hit? 1 Answer

Fnaf Rebot, not working with, Door. 1 Answer

Static member cannot be accessed 0 Answers

good way to get reference of transform of newly instantiated player object? 0 Answers

See the battery on GUI 1 Answer


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