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.
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