Question: OtherScript = otherScript = GetComponent<OtherScript>();

[SOLVED]
I didnt put the 2nd script on the same game object

Hello all…ran into my first problem of many more problems to come lol

I am trying to access a simple function from my other class. I keep getting this error:

NullReferenceException: Object reference not set to an instance of an object
GameManager.Update () (at Assets/GameManager.cs:16)

here is my code:

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {
	
	Controller controller;
	
	void Start ()
	{
		controller = GetComponent<Controller>();
	}
	
	
	void Update () 
	{
		controller.example();
	}
}
using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour {
	
	public void example()
	{
		Debug.Log("Controller");
	}
}

i have dragged the GameManager script to an empty GameManager object in the scene.
I have also dragged controller onto a gameobject in the scene.

please please please any help is appreciated!

Is both scripts at the same gameobject/prefab?

thanks for helping problem all solved :slight_smile: