How do I “push” a variable to another script to cause an action? [duplicate]
How do I “push” a variable to another script to cause an action? [duplicate]
This question already has an answer here:
Unity2D C#: I am looking for a way to "push" the chamberName variable from my Chamber script to my GUIManager script so it will actively add it to the text. I have found 1,000's of ways to pass variables between scripts, but none that actively cause the receiving script to take an action.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
C# Events, or UnityEvents, or custom Properties (setters), or function/method calls.
– Immersive
Sep 17 '18 at 8:13
1 Answer
1
Basically you need to get a reference to the GameObject with the other script attached, and call a public function in that script which will perform your action.
The GetComponent tutorial from the Unity website will help you understand this. It's only 3 minutes long and it covers how to get references to components on the same object as the attached script, as well as other objects.
It would be helpful if you could post the code and show us what you have tried so far.
– Immorality
Sep 14 '18 at 21:05