- Home /
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.
Best to just indent your code in $$anonymous$$onoDevelop by 4 spaces and paste it :)
I'm using tabs... No, they are not attached to the same object.
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?
$$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
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;
}
}
}
Your answer
Follow this Question
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