Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vivekahal · Oct 26, 2016 at 08:17 AM · displayspace shooterpointscounting

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..

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vivekahal · Oct 26, 2016 at 08:20 AM 0
Share

alt text

this is snap shot..

1.png (450.3 kB)

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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..

:) :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vivekahal · Oct 26, 2016 at 02:47 PM 0
Share

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.. :)

avatar image
0

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.. :)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Oct 26, 2016 at 01:32 PM 1
Share

Now you haven't dragged the reference into the scoreText slot of the inspector.

avatar image vivekahal tanoshimi · Oct 26, 2016 at 02:34 PM 0
Share

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)

avatar image vivekahal tanoshimi · Oct 26, 2016 at 02:43 PM 0
Share

Still it shows error

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges