- Home /
How to access .int variable?
What is the syntax for accessing .int variables in unityscript?
GameObject.Find("theSCRIPTgameobject").GetComponent(theSCRIPTcomponent).???;
Answer by Pysassin · Jan 23, 2013 at 01:26 AM
If you are trying to locate a variable in another script you simple call the variable name. something like...
var thisInt : int = GameObject.Find(targetObject).GetComponent(targetScript).intVariableName;
by inVariableName, do you mean that entirely as the name, or do you literally put INT+WhateverName?
var theGameObject : GameObject = GameObject.Find(targetObject);
var theComponent : TargetScript = theGameObject.GetComponent( TargetScript );
var theVarThatIsAnInt : int = theComponent.theVariableOnTargetScriptThatIsAnInt;
=]
@alucardj possible to do it as a one liner?
EDIT:Not one line, but this works. For some reason it doesnt like to be defined as int in the same line.
var newIntVar : int;
newIntVar = GameObject.Find(theobject).GetComponent(thecomponent).oldIntVar;
which was how I was doing in the script already but wanted as one line.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Get object, which is more optimized? 1 Answer
Shared variable problem, between scripts, help? 1 Answer
Semicolon error using JS 1 Answer