So I am trying to make a 2d game and I came up with a problem: I was trying to create a script that destroys the main character when he and the enemy collide. The enemy already has a script that makes him run from left to righ and right to left in a certain spot. When I simple run into the enemy it works fine, but when my player stays still in a spot and the enemy runs into the player, the enemy just goes through the player and continues to walk back and forth.
Here is the script:
#pragma strict
var Limite : GameObject;
var Player : GameObject;
var spawnPoint : Transform;
var Tag = "";
function OnTriggerEnter (other : Collider)
{
if (other.CompareTag (Tag))
{
Limite.audio.Play();
Destroy (other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
}
}
Also: I didn’t get any errors.