- Home /
Using a function from another script
Hey. I know this has been asked many times, but somehow I cant find any good answer.
I have made a function in one class, and I'd like to use it in another.
In one thread there was an answer including creating an instance, where you were writing something like "public Instance [class name here]" and then, when you wanted to use a function from this class "[function's class name].Instance.[function name and so on]".
Thank you for any help.
Answer by Natsu_k · Jan 15, 2015 at 03:21 AM
For the code to run it needs to exist somewhere within the game, not just in your assets folder. Which gives you 2 options, the first being what you've said in your question and the second being to add the function to the script your trying to call it in.
Edit: Also creating the class as a variable in a script would be more elegant then having a gameObject "House" the script for you; at least that way in the script it can be disposed of when it goes out of context.
Your answer

Follow this Question
Related Questions
OBJ runtime import 1 Answer
How to call a function from another script in C# from array? 1 Answer
How to use yield within a class function 2 Answers
Help with UnityException Error 1 Answer
Function Update and error UCE0001 3 Answers