Help instantiating object

When I execute the next code, I see this error:
NullReferenceException: Object reference not set to an instance of an object
GameManager.Start () (at Assets/Scripts/GameManager.cs:15)

I need to change “velocity” variable, from another class.
The objects with tag “Block”, have a script component named “MoveManager.cs”

Should I provide more info?

public class MoveManager : MonoBehaviour {
   int velocity = 2;

   public void SetVelocity (int newVelocity) {
     velocity = newVelocity;
     }
}

==============================================================

public class GameManager : MonoBehaviour {
   int road = 2;
   MoveManager gameObj;

   void Start (){
     //next is line 15
     gameObj = GameObject.FindGameObjectsWithTag ("Block").GetComponent<MoveManager> ();
     InvokeRepeating ("ChangeRoad", 5, 5);
   }

   void ChangeRoad (){
     road = Random.Range (1, 4);
     //I can see a Debug here
     gameObj.SetVelocity (road);
     //I can't see a Debug here
   }
}

Regards.

FindGameObjectsWithTag returns an array, you appear to be assigning it to “not an array”… also, the error line number is 15, but the code you’ve pasted in is missing it’s “usings” at the top, so it’s hard to tell where the error is occurring.

Yes there is a compiler error in this code, but it should not be the one you are getting.
As LeftyRighty already said, GameObject.FindGameObjectsWithTag returns an array, which does not contain a member called GetComponent but is called anyways.

gameObj = GameObject.FindGameObjectWithTag ("Block").GetComponent<MoveManager> ();

I suppose you have used this method without the s in it and made a mistake when pasting it here, so my guess would be that there is no game object with the tag “Block” in the scene so the search returns null.

using UnityEngine;
using System.Collections;

I am going to review carefully next functions, maybe here is the problem:
GameObject.FindWithTag
GameObject.FindGameObjectWithTag
GameObject.FindGameObjectsWithTag

Thank you very much.