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 AMDAndrew · Oct 07, 2012 at 01:03 PM · javascriptgetcomponentvariables

variable scope problem

I would like to invoke from another script ( Switch ) a boolean called "opened". I would like to know what I am doing wrong as my variable "open" it's not taking value true.

 #pragma strict
 
 var open;
 var opened : boolean = false;
 
 function Start () {
     
     var yes : Switch = GetComponent(Switch);  
     open = yes.opened;
     
 }
 
 function Update () {
 
     if( open == true){
         animation.Play("RockMove");
         opened = true;
         }
 
 }

Thank You.

EDIT

:I have tryied everything I could

static .1

-Use-and142062-d.com/threads/3http://forum.unity .2

change-a-variable-of-another-script function Start () { // Find the OtherScript which is .3 : attached to any game object in the scene. var other ;)OtherScript = FindObjectOfType(OtherScript

} ;)(other.DoSomething

Q66Scripts : http://pastebin.com/QFLzS Yftk7http://pastebin.com/DkH

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 AMDAndrew · Oct 07, 2012 at 03:19 PM 0
Share

Declaring yes before start function will cause an error that will say to declare it in start, and it won't play the animation 500 times per sec. Yes it's a poor name but I was just testing. I hate global variables.

avatar image Eric5h5 · Oct 07, 2012 at 06:14 PM 0
Share

Update runs once per frame, not 500 times per second.

avatar image AMDAndrew · Oct 07, 2012 at 07:18 PM 0
Share

I have tryied everything I could:

  1. static

  2. http://forum.unity3d.com/threads/142062-Use-and-change-a-variable-of-another-script

  3. function Start () { // Find the OtherScript which is attached to any game object in the scene. var other : OtherScript = FindObjectOfType(OtherScript); other.DoSomething(); }

Scripts : http://pastebin.com/QFLzS66Q

http://pastebin.com/DkH7Yftk

1 Reply

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

Answer by Fattie · Oct 08, 2012 at 05:26 AM

try this champ

 #pragma strict
 private var otherScript :Start;
 function Awake()
 {
 otherScript = GetComponent(Switch);
 if( otherScript == null ) Debug.Log("SOMETHING IS WRONG");
 }
 
 function Update ()
 {
 if( otherScript.opened )
 Debug.Log("the variable is true");
 else
 Debug.Log("the variable is false");
 }
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 AMDAndrew · Oct 08, 2012 at 02:05 PM 0
Share

I am sorry to say but we are noobs. Thanks to your logs I saw that the variable was not taking value of true.

In the first script

opened = isOpened;

in Awake function, that means it will stay forever false. Just had to put it in Update.

avatar image AMDAndrew · Oct 08, 2012 at 02:38 PM 0
Share

$$anonymous$$an calm down I'm not that mean, I pressed after I got it but porobably didn't worked :))

avatar image Eric5h5 · Oct 08, 2012 at 03:46 PM 0
Share

Not as nuts as people who consistently post answers as comments, making it impossible for the question-asker to accept the answer, and who always delete their comments, making for comment threads that make no sense. cough ::looks at Fattie meaningfully::

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

12 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

Related Questions

fix script to get C# var from another object instead of object this script is attached to 2 Answers

Can 2 scripts attached to one object communicate with each other? 2 Answers

Stupid question about public / private variables 2 Answers

Script is setting variables but they're being reset 1 Answer

How do I access a script variable from a class defined within that script? 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