Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How to make a WinText after killing the last enemy?

$
0
0
I have several objects (any number). After destroying everyone in the right order (e.g 1-4) should appear: "YouWin". Unfortunately, I do not know how to creating a method on a central square, when a correct square (LAST SQUARE) is destroyed. The central object would have to know the last number (or total number needed to win). Could someone help you? **Script in my central object:** using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Gamer : MonoBehaviour { int index =1; public GameObject gameOverText, restartButton ; public GameObject WinningText, ExitButton, NextLevelButton ; public GameObject Manager; void Start () { gameOverText.SetActive (false); restartButton.SetActive (false); Manager.SetActive (true); WinningText.SetActive (false); ExitButton.SetActive (false); NextLevelButton.SetActive (false); } public void OnCollisionEnter2D (Collision2D col) { Debug.Log("Player hit object: " + col.transform.name); //check if the object you hit is one of the "collisionObjects": if(col.transform.GetComponent()) { collisionObject colObj = col.transform.GetComponent(); if(!colObj) return; if(index == colObj.myIndexNumber) { Destroy(col.gameObject); index++; } // here, we know it didn't match the number. :) else { gameOverText.SetActive (true); restartButton.SetActive (true); gameObject.SetActive (false); Manager.SetActive (false); } } } } **Script on the destroyed object:** public int myIndexNumber; public void Start() { Debug.Log("Object number " + myIndexNumber + " is here"); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>