Collider is deleting itself when I press play
So I am working on a little "start-up" project where I am making my own game. I'm still relatively a beginner, and thought I'd try to make a little something :). It is basically a player jet flying through a little gorge trying to kill as many enemies as possible while trying to stay alive. But I have a problem with the enemy game object. For ease, I duped the Player "Plane" object and renamed it to "Enemy", and took out the script for the player game object, and added a new script that deals with the enemy movement and shooting. The player has a box collider, which I have coded correctly to interact with the enemy collider. But the enemy Box collider deletes itself when I hit play. What's more, the actual component in the inspector disappears as well. I am so confused as to why this is happening, and have tried everything I can to fix it. I even tried re-doing the whole enemy game object, and replacing it with a new object and code, but that didn't work. I have some player boundaries, but they only interact with the player, and to make sure that this is the case, I have made it so that only objects with the tag "Player" are affected. I have been trying to fix this for about a week and it is so annoying!!
Please help if u can, thanks in advance!
Here is the code(which is all fairly similar) I use for the enemy, the code for destroying the player, removing the shots, and for destroying the enemy
Enemy code:
using UnityEngine;
using System.Collections;
public class EnemySortOut : MonoBehaviour
{
public GameObject Shot;
public Transform ShotSpawn;
public float FireRate;
public float ForwardPush;
private float NextFire;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate ()
{
if (Time.time > NextFire)
{
NextFire = Time.time + FireRate;
Instantiate (Shot, ShotSpawn.position, ShotSpawn.rotation);
}
rb.velocity = (transform.forward * ForwardPush);
}
}
Destroying the player:
using UnityEngine;
using System.Collections;
public class PlayerDestroy : MonoBehaviour {
public AudioSource PlayerDestroySound;
public GameObject PlayerExplosion;
void Start ()
{
PlayerDestroySound = GetComponent<AudioSource> ();
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player")
{
Instantiate (PlayerExplosion, other.transform.position, other.transform.rotation);
PlayerDestroySound.Play ();
Destroy (other.gameObject);
}
}
}
Removing the shots:
using UnityEngine;
using System.Collections;
public class ShotRemover : MonoBehaviour
{
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Shot")
{
Destroy (other.gameObject);
}
if (other.gameObject.tag == "Player")
{
other.gameObject.SetActive (false);
other.gameObject.SetActive (true);
}
}
}
Destroying the enemy:
using UnityEngine;
using System.Collections;
public class EnemyDestroyer : MonoBehaviour
{
public AudioSource EnemyDestroySound;
public GameObject EnemyExplosion;
void Start ()
{
EnemyDestroySound = GetComponent<AudioSource> ();
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Enemy")
{
Instantiate (EnemyExplosion, other.transform.position, other.transform.rotation);
EnemyDestroySound.Play ();
Destroy (other.gameObject);
}
}
}