- Home /
Question by
jtok4j · Jun 28, 2018 at 04:31 PM ·
scripting beginner
Do I have this right? Getting a variable value from another script using a JS function and Return
Quick Question to see if I'm interpreting this line of code (JavaScript/UnityScript ) correctly:
/*
* FUNCTION: Get the currency collected in current run
*/
public function getCurrencyUnits() { return iCurrencyUnits; }
^ On this script is a variable named iCurrencyUnits.
On another script, a call is made to the above function. (shown below)
tmHUDCurrencyText.text = hPowerupsMainController.getCurrencyUnits().ToString(); //update Currency on HUD
I was surprised and confused to see the top function was essentially blank, except for the "return iCurrencyUnits" that I saw at the end of the line.
So, not using JavaScript very often, I wonder if this retrieves the variable amount from the first script and delivers it to script 2 for easy reference?
Thanks for your input/feedback.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612165650im_/https://answers.unity.com/themes/thub/images/avi.jpg)