So, I have my Beam projectile able to destroy enemies. However, I want it to be able to destroy itself when it collides with any object, whether it be an enemy, terrain, or any solid object it touches.
public class DestroyBeamProjectile : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
if (collision.collider.gameObject.tag == "EnemyBody" || collision.collider.gameObject.tag == "EnemyHead" || collision.collider.gameObject.tag == "Enemy")
{
if (collision.collider.gameObject.tag == "EnemyHead")
{
Destroy(collision.collider.transform.parent.gameObject);
Destroy(collision.collider.gameObject);
GameManager.score += 100;
Debug.Log(GameManager.score + " points!");
}
else if (collision.collider.gameObject.tag == "EnemyBody" || collision.collider.gameObject.tag == "Enemy")
{
Destroy(collision.collider.gameObject);
GameManager.score += 100;
Debug.Log(GameManager.score + " points!");
}
}
}
}
I have it set to destroy an enemy if it comes in contact with it, but I need it to destroy itself if it comes into contact with any solid object. If this can be done using tags, I would like the script to do that.