- Home /
How to call a function from another script without referencing it?
I'm trying to make a simple script to save and reuse resources instead of instantiating and destroying them all the time. However, I don't understand how do I call these functions without referencing them on the scripts...
I want to do something like iTween, where you only need the script on your folder to be able to call "iTween.MoveTo" and all the other functions. I tried to open and mimick it, but it still gave me errors with my functions, saying that I need a reference to call the functions. How do I do it without referencing, like iTween? I'm using C#
Answer by robertbu · Aug 11, 2014 at 07:12 PM
If you declare your functions as 'static' then you can call them with just the class name. So if I had a class called 'Test' with this function:
public static int TimesThree(int x) {
return x * 3;
}
I could do this:
int i = Test.TimeThree(j);
But these functions cannot access any class instance variables of the class.
For a class that has just helper methods consider making the entire class static.
I believe you can also use Send$$anonymous$$essage for this. Never used it though, so don't quote me on that :P
It's slow and better for broadcast to many objects.
Your answer
Follow this Question
Related Questions
How to reference another script and call a function in C# ? 2 Answers
Call GUITexture and script 1 Answer
How to call a function in another script 3 Answers
Calling a Function from other script ( C# ) 1 Answer
Call function in another script? 1 Answer