- Home /
Duplicate Question
How do i call a function from another script in another object
I got to scripts that are in two different objects. I need script 'A' to call a function in script 'B'. and script 'B' is in a different game object, How do I do this?
I know this is a bit late but: You probably have to make the function public on the other game object.
That solved my problem.
Answer by Landern · Jan 01, 2015 at 05:34 AM
This is asked WAY to often to not try and search for the answer yourself.
From unity docs:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
From unity forums:
http://forum.unity3d.com/threads/calling-function-from-other-scripts-c.57072/
From unity answers:
http://answers.unity3d.com/questions/7555/how-do-i-call-a-function-in-another-gameobjects-sc.html
http://answers.unity3d.com/questions/13248/how-to-call-a-function-from-another-script-getting.html
http://answers.unity3d.com/questions/366095/how-to-call-a-function-from-a-script-component-on.html
http://answers.unity3d.com/questions/10857/how-can-i-access-other-scripts-and-their-functions.html
From YouTube:
http://answers.unity3d.com/questions/10857/how-can-i-access-other-scripts-and-their-functions.html
and on and on and on.
"This is asked WAY to often" So what does that tell you???????
What are you getting at? Have you read the FAQ?
If a question has been asked and answered here many times already, it tells me the answer should be easy to find by searching (as the answer points out). Asking the same question again doesn't help anyone in any way. Neither does resurrecting 2 year old questions.
Straight from Unity Answers FAQ: (about differences between Forums and Answers)
One problem with the Unity Forums was that old threads tended to get buried, so users ended up asking the same questions over and over again.
And also
Please look around to see if your question has already been asked (and maybe even answered!) before you ask. If you end up asking a question that has been asked before, it may end up getting rejected in the moderation queue or closed if it has been published. Other users will hopefully edit in links to related or similar questions to help future visitors find their way.
Just wanted to post here, the reason this is still being asked is because half of the answers do not work. Your does. The first link is dead but the second has the solution:
YourGameObject.GetComponent<YourScript>().YourFunctionInScript(Parameters);
Follow this Question
Related Questions
Sending data to different game objects? 1 Answer
Delay befor Jump with character controller 1 Answer
How to control Another Object by using other one 1 Answer
How do I right this Java Script code in C# 1 Answer
Is there a quick way to de-activate a game object and all its children in script? 1 Answer