Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Feedback Enemy detection build bug

Discussion in '2D' started by JackAshwell, Oct 23, 2019.

  1. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    So this is my current script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EndGame : MonoBehaviour {
    6.  
    7.     void OnGUI() {
    8.         if (GameObject.FindWithTag ("Enemy") == null) {
    9.             Debug.Log("Enemy not found");
    10.            
    11.             GUI.Label( new Rect(Screen.width/2 -50, Screen.height/2 -25, 100, 50), "Congratulations, you won! Restart the game!");
    12.         }
    13.     }
    14. }
    And it works when i play it in the editor, but when i build the game and run the executable. It just shows Congratulations, you won! Restart the game! continuously. It shouldn't do that.

    Please help!

    Thanks!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
  3. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    It works in the editor, so why shouldn't it work in the build then?

    And all the enemies have the "Enemy" tag.
     
  4. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    Damm, i only tagged the enemies that are in the project window. Not the ones that are prefabs. Me dumb, don't worry