So I have a player that needs to pass through the enemy and still have a life taken away. I cannot use OnCollision because then the physics of the enemy is transferred to the player. While I am playing lives are being taken away even though my player does not collide with my enemy. I have the enemy tagged to take a life away and i checked that no other objects contain this tag. Any help is appreciated. Attached is my GameOver script which really just takes a life.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameOver : MonoBehaviour
{
// Start is called before the first frame update
public Rigidbody2D rb;
public LifeManager lifeSystem;
public GameObject GameOverScreen;
public float waitAfterGameOver;
void Start()
{
rb = GetComponent<Rigidbody2D>();
lifeSystem = FindObjectOfType<LifeManager>();
}
public void OnTriggerEnter2D(Collider2D trigger)
{
if (trigger.gameObject.tag == "Ghost")
{
lifeSystem.TakeLife();
}
if (GameOverScreen.activeSelf)
{ waitAfterGameOver -= Time.deltaTime; }
}