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 geennaam · Jun 19, 2012 at 05:00 PM · variablevariableslink

Link 2 variables from 2 different scripts to 3rd script

Hello, I've asked a question here before because I didn't understand how to link a variable from another script. But my next question is how to get another variable to that script to. By example:

testInput.js

  var testVariable = 1;
  var to : testOutput; // Assign it in the inspector
  function Update()
  {
      if( Input.GetKey("k") )
      {
          testVariable= 5;
          to.UpdateAnotherVariable( testVariable );
      }
  }

testOutput.js

  var anotherVariable = 0;
  function UpdateAnotherVariable( i : int )
  {
      if( i == 5)
      {
          if()// if finalVariable from finalScript.js == 10. (here is the

problem)

          anotherVariable = 1;
      }
  }

finalScript.js

  var finalVariable = 5
  function Update
  {
      if(finalVariable == 5)
      {
          finalVariable = 10;
      }
  }


Sorry for all that spaces, but that's because of a problem with the editor :S.

Comment
Add comment · Show 10
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 whydoidoit · Jun 19, 2012 at 05:01 PM 0
Share

Best to just indent your code in $$anonymous$$onoDevelop by 4 spaces and paste it :)

avatar image whydoidoit · Jun 19, 2012 at 05:02 PM 0
Share

So are these scripts attached to the same object ?

avatar image geennaam · Jun 19, 2012 at 05:07 PM 0
Share

I'm using tabs... No, they are not attached to the same object.

avatar image whydoidoit · Jun 19, 2012 at 05:08 PM 0
Share

So tell me how these objects are related - because you are going to need to establish those relationships. Is one of them maybe a single instance?

avatar image geennaam · Jun 19, 2012 at 05:15 PM 0
Share

$$anonymous$$y English is not very good, but I understand you right is instance the child/parent relation between objects? If that's true, yes, they are all single, they have no relation with eachother

Show more comments

1 Reply

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

Answer by whydoidoit · Jun 19, 2012 at 05:33 PM

So you can try this - note you should really call it FinalScript to indicate that it is a class. Drag and drop your final script object onto test output.

 var anotherVariable = 0;
 var final : finalScript;
 function UpdateAnotherVariable( i : int )
 {
     if( i == 5)
     {
        if(final.finalVariable == 10 {
             anotherVariable = 1;
         }
 
     }
 
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Linking 2 script variables (min + max) to one editor bar - MinMaxSlider? 0 Answers

Easily cleaning up \ deleting unused variables? 2 Answers

How to link this 2 variables from 2 different scripts / gameobjects? 1 Answer

Calling a static variable (not working) 1 Answer

How to make variable public "In whole script" from update function? 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