Quantcast
Channel: Answers for "How do I call methods from other scripts using C#?"
Viewing all articles
Browse latest Browse all 6

Answer by Peter G

$
0
0
My guess is that it is comming from this line: mUI.GamePauseGUI(); Unity does not automatically connect references except for built in accessors such as `.transform`. You need to manually reference the UI_Manager GameObject in order to use it. This can be done a number of ways, here's an example. public class Game_Manager : MonoBehaviour { private static Game_Manager thisInstance; private static GameState mGameState; //------------------------- private UI_Manager mUI; private UI_Manager MUI { get { if(mUI == null) { mUI = (UI_Manager)FindObjectOfType(typeof(UI_Manager)); //^ this is the important line. } return mUI; } } //------------------------- public void GamePause() { /*use the property MUI to call your methods*/ } } The important part of the above example is `mUI = (UI_Manager)FindObjectOfType(typeof(UI_Manager));`. The method finds an object of the given type in the scene and returns it. You need to cast it to its derived type though 95% of the time before you actually use it.

Viewing all articles
Browse latest Browse all 6

Trending Articles