Hey there. Im making a top down shooter game. Soo my question is I have an enemy script that has :
public void TakeDamage(float damage)
{
healt -= damage;
if(healt <= 0)
{
Destroy(gameObject);
}
}
And then I have a weapon script (pickupble weapon) and a bullet prefabe that I Instantiate.
So when bullet collide with enemy:
private void OnCollisionEnter2D(Collision2D other)
{
Weapon weaponScript = other.gameObject.GetComponent<Weapon>();
if (other.gameObject.TryGetComponent<Enemy>(out Enemy enemyComponent))
{
I WANT TO MAKE LIKE THIS BUT I CANT
enemyComponent.TakeDamage(weaponScript.damage);
LIKE THIS IS WORKING
enemyComponent.TakeDamage(1);
Debug.Log("hitsomethings");
}
Destroy(gameObject);
}
Soo i want deal damage with the public float that weapon script has when bullet script collide with enemy then enemy take damage.
Is that possible? Im doing like this cause there is different weapons soo different fireRate,damage,etc…