C# - Access a script's function within another script?

I’m a little unsure on how to access a function from one script within another.

If I had, say, object1 with script1 containing function test, how would I find and call test from script2 attached to object2?


There’s more than one way to solve this.

Here’s a pretty easy way to do it:
In script1 put

public class script1 : Monobehaviour
       public script2 secondScript;

       void Update()

After making your script, save it and go to the unity editor.
When you are in the editor select object1 in the hierarchy so it appears in the inspector. Drag object2 from the hierarchy onto the secondScript variable in the inspector. It will auto detect that object2 has script2 and will fill secondScript’s value with script2.

Edit: Don’t forget to make sure script two has a function called test!

Press Play and you should be good to go.