Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Moving to the "Results" scene after the player killed all the enemies in the field

Discussion in 'Editor & General Support' started by Watamaru, Dec 8, 2018.

  1. Watamaru

    Watamaru

    Joined:
    Sep 9, 2018
    Posts:
    1
    Hello there,

    I'm making a TPS, and trying to show the "Results" once the player killed all the enemy in the "Main" scene.
    I'm using the script below, but nothing happens.

    What am I doing wrong? Maybe I stored this script in a wrong place?
    (I made a "Scripts" folder in the Project tab)

    Any help will be appreciated.

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

    using UnityEngine;
    using System.Collections;
    using UnityEngine.SceneManagement;

    public class GameClearController : MonoBehaviour {


    private GameObject[] enemyObjects;

    void Update () {


    enemyObjects = GameObject.FindGameObjectsWithTag("Enemy");

    print(enemyObjects.Length);


    if(enemyObjects.Length == 0){


    SceneManager.LoadScene("Results");
    }
    }
    }


    =======================================================================-