- Home /
Question by
LEDCat64 · Dec 12, 2020 at 12:07 AM ·
2derrorcollision detectionontriggerenter2dunused
"Private member OnTriggerEnter2D is unused"?
I've been having an issue with my script where my projectiles don't collide with the enemy at all. Using debug logs, the projectiles will pass through my enemy and shows that no collision is happening.
I have both set to interact based on triggers, however I noticed the titular message on my enemy script. It tells me that the OnTrigger function isn't being called. This doesn't occur in my projectile script, so it seems this is where my issue lies, but I don't know how to fix it.
The script I've written:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EnemyHealth : MonoBehaviour
{
public int health = 1; //amount of health
public Transform player;
public Transform projectile;
public GameEnding gameEnding;
public void TakeDamage(int damageAmount)
{
health -= damageAmount;
if (health <= 0)
{
Destroy(gameObject); //kills enemy once health reaches 0
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.transform == player)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
//else
if (other.transform == projectile)
{
TakeDamage(1);
Debug.Log("enemy hit");
}
}
}
Comment