- Home /
cant destroy other object
So I have created a character that can shoot and some things to shoot at, and that all works well and good. However, I want the bullets to destroy the objects they collide with (they happen to be clones from another object that are being launched) and I have no Idea why my code isn't working. Any help?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class enemyhp : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "enemy")
{
Destroy(other);
Debug.Log("Collided");
}
}
}
Comment
Best Answer
Answer by jchester07 · Dec 05, 2017 at 03:37 AM
Should be Destroy(other.gameObject)
Else it will just destroy the Collider of "other"