Not sure how this process works so i’m having trouble having a bullet damage an object if it’s an enemy.
Bullet code:
private Rigidbody rb;
public float speed;
public float damage;
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
void Update ()
{
rb.velocity = transform.forward * speed;
Destroy (gameObject, 3.0f);
}
void OnCollisionEnter (Collision collision)
{
if (//if the collision was with an enemy)
{
//pass bullets damage into enemy's damage method
}
}
Enemy code:
public float health;
void Update ()
{
if (health <= 0)
Destroy (gameObject);
}
void TakeDamage (float damage)
{
health -= damage;
}