I am creating a small top down shooter prototype, and the way the bullet object is set up is it has a trigger collider, and when it collides with something, it checks if the objects is an enemy, and if it is, it damages the enemy. for some reason, the bullet is not registering when it hits an enemy, or any other object, just the player object. here is the script for the bullet:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullets : MonoBehaviour
{
public float speed;
public LayerMask whatToHit;
public int DMG;
// Update is called once per frame
void Update()
{
transform.position += transform.forward * Time.deltaTime * speed;
}
void OnTriggerEnter(Collider other)
{
Debug.Log("hit: " + other.gameObject.name);
if (other.gameObject.layer == whatToHit)
{
other.gameObject.GetComponent<health>().takeDMG(DMG);
Destroy(this.gameObject);
}
}
}
an object with this script, a script that deletes it after 15 seconds, and a trigger collider is instantiated every time the player shoots, but the OnTriggerEnter is only registering the player object. here is a video of the issue.
this solved it! thanks!
– JohnnyOlBoy