For very simple multi-language support in my project, I’ve added a function to the GameController script (JS) that returns a String depending on the language. But every time I try to assign that returned String to a GUIText (or even to a String variable I get a type cast error.). I’m new to JavaScript.
Here’s the sample code for GameController.js
function Hello()
{
return "hello";
}
Code from the actual script attached to another GameObject
var x : String = GameObject.Find("GameController").GetComponent("GameController").Hello();
Even that gives me an “InvalidCastException: Cannot cast from source to destination type.”
Thanks for the help! That really does the trick for that bit of code.
But what do I do if I need to pass a parameter?
What I really want to do is something like calling Hello(language:int) that returns a String in a language (I use a “dictionary” Array that returns a String based on the given language).
I also tried to declare my function as
function Hello() : String
{
return "Hello";
}
but this didn’t do it either (same exception, no complains about the “: String” bit though)