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");
}
}
↧