- Home /
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..
Answer by vivekahal · Oct 27, 2016 at 04:15 AM
Thank you everyone...
I changed "Gamecontroller" to "GameController"..It's working now..
Thank you everyone for the help..
:) :)
Answer by hexagonius · Oct 26, 2016 at 08:26 AM
If the tag is not defined then you need to define it under Edit -> Project Settings -> Tags and Layers
Answer by tanoshimi · Oct 26, 2016 at 08:31 AM
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.
Thanks for the reply..@tanoshimi..
I tagged in Prject settings..I got some 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 ga$$anonymous$$g..
Thank you.. :)
Answer by vivekahal · Oct 26, 2016 at 01:28 PM
@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.. :)
Now you haven't dragged the reference into the scoreText slot of the inspector.
ok ok..It's there ..I added ScoreText in inspector..
Cannot find 'Gamecontroller'script UnityEngine.Debug:Log(Object) Destroybycontact:Start() (at Assets/Scripts/Destroybycontact.cs:20)
Your answer
Follow this Question
Related Questions
I need to alter all instances of a prefab? 1 Answer
Problem with duplicated score! 1 Answer
C# Invalid Points Assigned to 2D Edge Collider 1 Answer
I am having trouble assigning public gameObjects 3 Answers
Count Deaths 2 Answers