NavMesh + OnCollision Destroys Enemy but not Player

Hi all,
I am trying to make the Enemy destroy the Player and the Enemy GameObject on contact, but currently, the OnCollision would only destroy the Enemy GameObject and not the Player.

Prefab Navigator (Tag “Player”)
Prefab Enemy (Tag “Enemy”)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDead : MonoBehaviour {
    public GameObject Player;

    // Use this for initialization
    void OnCollisionEnter(Collision EnemyCollide)
    {
        if (EnemyCollide.gameObject.tag == "Player") 
        {

//            returns error:
//            Destroying assets is not permitted to avoid data loss.
//            If you really want to remove an asset use DestroyImmediate (theObject, true);
            Destroy (this.gameObject);
            Destroy (Player);

//            returns error: 
//             Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead.
//             UnityEngine.Object:smile:estroyImmediate(Object, Boolean)   
//            DestroyImmediate (this.gameObject, true);
//            DestroyImmediate (Player, true);
        }
    }
}

Furthermore, upon destruction of the Enemy GameObject, I would receive either error in both cases. I really want to destroy both the Player and Enemy. Thanks.

Hello? Anyone?

DestroyImmediate (Player.gameObject);

or DestroyImmediate (Player.gameObject, 0.1f);

Now I am getting two errors:
Assets/Scripts/PlayerDead.cs(23,4): error CS1502: The best overloaded method match for `UnityEngine.Object.DestroyImmediate(UnityEngine.Object, bool)’ has some invalid arguments

Assets/Scripts/PlayerDead.cs(23,41): error CS1503: Argument #2' cannot convert float’ expression to type `bool’

That was suppose to be Destroy(ssry about that); However here you are this should destroy both enemy and player, and be sure to have isTrigger checked ON, on your player game object… let me know if this worked for you.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDead: MonoBehaviour {
    public GameObject Player;



    // Use this for initialization
    void OnTriggerEnter(Collider EnemyCollide)
    {
     
        if (EnemyCollide.gameObject.tag == "Player")
        {
            Destroy (this.gameObject);
            Destroy (Player.gameObject);
        }
    }
}

Nope it doesn’t work, I set the collider istrigger only to the player game object.

The error that you have listed in the comments in your code suggests that you’re trying to destroy an asset (prefab) and not an instance object in the scene. If that is still true, fix that so you’re not doing that.
For instance, if the game object you’re colliding with is the player, use that variable to destroy the player instead of the referenced object (can’t tell which object was giving that commented error).