Hi,
I need to access a function in a different script by entering it’s name in Editor. Here is my setup so far:
SCRIPT 1: FnCollection.js
//FUNCTION COLLECTION SCRIPT//
private static var instance : FnCollection = null;
static function I() : FnCollection
{
if(instance == null)
{
instance = FindObjectOfType(FnCollection);
}
return instance;
}
function PrintStuff()
{
print("hello");
}
SCRIPT 2: FnRunner
//FUNCTION RUNNER SCRIPT//
var fnToRun: String;
function Start()
{
FnCollection.I().fnToRun();
}
However, it doesn’t work because “fnToRun is not a member of FnCollection”. This is obvious but how else can I access the function through it’s name being retrieved from a string that is editable in the Inspector in the Unity Editor?
I need to have access like this as I plan on putting all my general functions into FnCollection and accessing them when I press buttons and from other scripts.
Thanks
Thank you man. I've been looking for this for like 3 hours. I really appreciate your help.
– anon73710387