37 lines
947 B
C#
37 lines
947 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class TriggerEnableAndDisable : MonoBehaviour{
|
|
|
|
public GameObject enable;
|
|
public GameObject disable;
|
|
public float delay;
|
|
|
|
void OnTriggerEnter2D(Collider2D col){
|
|
if(col.gameObject.tag == "Player"){
|
|
if(delay == 0){
|
|
if (enable != null){
|
|
enable.SetActive(true);
|
|
}
|
|
if (disable != null){
|
|
disable.SetActive(false);
|
|
}
|
|
gameObject.SetActive(false);
|
|
}else{
|
|
StartCoroutine(Delay());
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator Delay(){
|
|
yield return new WaitForSeconds(delay);
|
|
if (enable != null){
|
|
enable.SetActive(true);
|
|
}
|
|
if (disable != null){
|
|
disable.SetActive(false);
|
|
}
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|