UnityException: Tag: Gamecontroller is not defined.@Space shooter tutorial..

Hello everyone…

I’m following the Space shooter tutorial by unity…I got an error while doing Counting points and displaying the score.My game stops and shows me error.

And this is the error…

UnityException: Tag: Gamecontroller is not defined.
UnityEngine.GameObject.FindWithTag (System.String tag) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:297)
Destroybycontact.Start () (at Assets/Scripts/Destroybycontact.cs:13)

Please help me find the error…

Here is my code for (Destroybycontact script)…

using UnityEngine;
using System.Collections;

public class Destroybycontact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
private Gamecontroller gameController;

void Start()
{
	GameObject gameControllerObject = GameObject.FindWithTag ("Gamecontroller");
	if (gameControllerObject != null) 
	{
		gameController = gameControllerObject.GetComponent<Gamecontroller> ();
	}
	if (gameController == null) 
	{
		Debug.Log ("Cannot find 'Gamecontroller'script");
	}
}
void OnTriggerEnter (Collider other)
{
	if (other.tag == "Boundary")
	{
		return;
	}
	Instantiate (explosion, transform.position, transform.rotation);
	if (other.tag == "Player") {
		Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
	}
	gameController.AddScore(scoreValue);
	Destroy (other.gameObject);
	Destroy (gameObject);
}

}

Gamecontroller Script is…

using UnityEngine;
using System.Collections;

public class Gamecontroller : MonoBehaviour
{
public GameObject hazard;
public Vector3 spawnValues;
public int hazardCount;
public float spawnWait;
public float startWait;
public float waveWait;

public GUIText scoreText;
private int score;

void Start()
{
	score = 0;
	UpdateScore ();
	StartCoroutine(SpawnWaves());
}

IEnumerator SpawnWaves()
{
	yield return new WaitForSeconds(startWait);
	while (true)
	{
		for(int i=0;i<hazardCount;i++)
		{
				Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
				Quaternion spawnRotation = Quaternion.identity;
				Instantiate (hazard, spawnPosition, spawnRotation);
				yield return new WaitForSeconds(spawnWait);
	    }
		yield return new WaitForSeconds(waveWait);
	}
}
public void AddScore (int newScoreValue)
{
	score += newScoreValue;
	UpdateScore ();
}

void UpdateScore()
{
	scoreText.text = "Score: " + score;
}

PLease anyone help me…

Thank you…

If the tag is not defined then you need to define it under Edit → Project Settings → Tags and Layers

The error is pretty descriptive - you’re trying to find a gameobject with the tag “Gamecontroller”, and you haven’t defined that tag in your project.
If you’re following the tutorial, you should have named the tag “GameController” (with a capital G), so try that.

@hexagonius …Thank you for your reply…

I defined the tag in project settings…Still had some problem here…It shows error…

NullReferenceException: Object reference not set to an instance of an object
Destroybycontact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Destroybycontact.cs:33)

Please help me…I’m new to gaming…

Thank you… :slight_smile:

Thank you everyone…

I changed “Gamecontroller” to “GameController”…It’s working now…

Thank you everyone for the help…

:slight_smile: :slight_smile: