How do you execute a script on a different GameObject and or its specific functions from within another script? Also how to connect scripts that are on different objects. Like for instance say I have a script for selecting stuff it can select anything in the game but it has ifs for each games tag, how then would I execute it to then use the functionality of a more specific script that has to do with what you selected?
Answer by Fattie
Aug 10, 2012 at 08:42 AM
this is explained in incredible detail with literally dozens of examples on the unity web site
notice the links "Accessing Other Components Accessing Other Game Objects"
If you ever have trouble finding unity documentation, using google just go "Unity3D documentation scripting reference other scripts"
And this has been asked dozen of times in Unity Answers. But it looks like that most users don't even bother using the search engine.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
8 People are following this question.
How to call a function from another script - getting error "Object reference not set to an instance of an object"
Callback never gets executed
NullReferenceException: Object reference not set to an instance of an object
Null reference when calling a method from another script
C'# When Taking Variables From Other Scripts, The Values Do Not Update