using UnityEngine;
public class Projectile : MonoBehaviour
{
public GameObject explosionVFX;
public Weapon damage;
void OnTriggerEnter(Collider other)
{
Debug.Log(other);
Destroy(gameObject);
Instantiate(explosionVFX, transform.position, transform.rotation);
if (other.GetComponent<EnemyHealth>() != null)
{
other.GetComponent<EnemyHealth>().TakeDamage(damage);
}
}
}
I have another script called weapon that has damage varibles and function I need on my projectile. No matter what I do it won’t work.
Right now your code is using composition rather than inheritance. Essentially, your projectile has a weapon, when you instead want your projectile to be a weapon. Change your Projectile class to inherit from Weapon instead of MonoBehaviour:
public class Projectile : Weapon