I have a mini game which has 4 objects and a gameobject that when is hovered over them, they should destroy themselves, but the script is not working properly.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DestroyTestCS : MonoBehaviour {
private int Seconds;
public bool isDestroyed = false;
private int count = 0;
public Canvas miniGameCanvas;
public Renderer rend;
void Start(){
rend = GetComponent<Renderer>();
rend.enabled = false;
}
void Update(){
}
void OnCollisionEnter2D (Collision2D col){
if (col.gameObject.tag == "laser") {
Destroy (gameObject);
}
}
public bool GetIsDestroyed(){return isDestroyed;}
}
I’ve tried OnTriggerEnter2D and OnCollisionEnter2D but none of them seem to work. Help is highly appreciated.