Getting Value from Function in another Script without knowing Script type
Hi all! I'm coding in Unityscript. I have a long list of string files I want to keep in separate scripts, attached to Dummy game objects. They all have the same functions: GetLengthOfStringFile(), GetSomeOtherValue(),...
I have another script that needs to be able to access these functions. It holds one of these dummy GameObjects with a corresponding "string file" kind of script attached.
var stringFile : GameObject;
//this function needs to get a value from a function in another script.
//I can't seem to find how to do so!
function ReadStuff() {
var x : int = 0;
//this doesn't work since the function isn't a member of GameObject
x = stringFile.GetLengthOfStringFile();
//this doesn't work since there isn't just one StringFile script, but many holding different
//lengthy Strings. I would need a switch or endless ifs to get the right component...
x = stringFile.GetComponent(StringFile).GetLengthOfStringFile();
//this doesn't work since SendMessage doesn't return a value.
x = stringFile.SendMessage("GetLengthOfStringFile");
//how do I get x to hold stringFile.GetLengthOfStringFile()?
}
Any idea how to get values from functions in different scripts, even though the type varies? They all have the same function names and return types. In Java this was fixed by using Interfaces. Is there some corresponding fix in Unityscript?
Your answer
Follow this Question
Related Questions
NullReferenceException on getComponent 1 Answer
Not sure how to make my classes interact in the way I intend them to 1 Answer
How to inherit from a class that inherits from MonoBehaviour 1 Answer
Get reference to dynamically added script 1 Answer
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer