I’m a beginner and I’m trying to get this code to check if an object collides with the player, and then have it do other things and then destroy the object. For some reason it keeps running twice? (No the script isnt on the object twice and no the code isn’t repeated)
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallingNotes : MonoBehaviour
{
public List<GameObject> list = RandomRhythm.randomRhythm;
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Debug.Log(gameObject.GetInstanceID());
//if (list.Count > 0 && gameObject.tag == list[0].tag)
//{
// Debug.Log(list[0].tag);
// Destroy(list[0]);
// list.Remove(list[0]);
//}
Destroy(gameObject);
}
if (collision.gameObject.layer == 6)
{
Destroy(gameObject);
}
}
}