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");
}
}
}
thanks, that was it.
– ragefordragonsYou can make
– Magsocarvaran array and in OnTriggerEnter usecarvar += [other.gameObject];if you want to limit it you can put that line underif(carvar.Length < numberOfCarvarAllowed)You can then get the boxcollider width by usingotherfrom the trigger or carvar[1] e.g.carvar[1].GetComponent<BoxCollider>().size.x