I have a collider on both the bullet and the Enemy Object and a rigidbody on the enemy and it still doesn't work. My bullets just go through the enemy. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Projectile_Move : MonoBehaviour
{
public float speed;
public float fireRate;
public GameObject ourObject;
public GameObject FirePoint;
// Start is called before the first frame update
void Start()
{
FirePoint = GameObject.Find("FirePoint");
this.transform.rotation = FirePoint.transform.rotation;
}
// Update is called once per frame
void Update()
{
if (speed != 0)
{
transform.position += transform.forward * (speed * Time.deltaTime);
} else
{
Debug.Log("NoSpeed");
}
void OnCollisionEnter (Collider col)
{
if (GetComponent().gameObject.tag == "Enemy") {
Debug.Log("Testing");
Destroy(gameObject);
Debug.Log("Processing");
speed = 0;
//if (col.gameObject.tag == "Enemy")
//{
// Destroy(gameObject);
// Debug.Log("object that was hit: " + ourObject);
// }
}
}
}
}
↧