- Home /
Question by
GordenRobison · Feb 06, 2018 at 06:04 PM ·
disableenable
Goal disabled while coins are present.
I have an object, that, when you collide with it, you advance onto the next level, but I want it to be disabled as long as there are coins in the level.,I have an object that, when you collide with it you advance to the next level, but I want to have it disabled as long as there are coins in the level.
Comment
Something like what Persian$$anonymous$$iller suggested would work. You can also have the coins register themselves at a global Level Object at the start, so you know how many coins are in the level without having to keep a count manually.
Answer by PersianKiller · Feb 06, 2018 at 06:18 PM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Checking : MonoBehaviour {
public GameObject nextLevel;
public void check(){
coins++;
if(coins>=10){
nextLevel.SetActive (true);
nextLevel.GetComponent<BoxCollider2D> ().enabled=true;
}
}
and coins script;
void OnTriggerEnter2D(Collider2D other){
if (other.CompareTag("player")) {
FindObjectOfType<Checking> ().check();
Destroy (gameObject);
}
}
so if you pick 10 coins then you can collide with that gameObject that let you go to the next level