I’m an artist,but have been asked to do some coding for my uni course so fairly baffled by all this coding stuff and have been following some tutorials.I have two scripts for my enemy, one marked as health that can be reference by both player and enemy, and an enemy health script that also controls score management on it. On enemy death I get this error message:
The variable deathEffect of EnemyHealth has not been assigned.
You probably need to assign the deathEffect variable of the EnemyHealth script in the inspector.
HEALTH
using UnityEngine;
public class Health : MonoBehaviour
{
[SerializeField]
protected int health;
[SerializeField]
protected int maxHealth;
public GameObject deathEffect;
public void TakeDamage(int amount)
{
health -= amount;
health = Mathf.Clamp(health, 0, maxHealth);
if (health <= 0)
{
Die();
}
}
public virtual void Die()
{
Destroy(gameObject);
Instantiate(deathEffect);
Destroy(deathEffect, 2);
}
public void MultiplyHealth(int amount)
{
health += amount;
ENEMY HEALTH
using UnityEngine.UI;
using UnityEngine;
using System;
public class EnemyHealth : Health
{
public int scoreValue;
public override void Die()
{
GameObject.Find("ScoreManager").GetComponent<ScoreManager>().AddToScore(scoreValue);
base.Die();
}
}
any help would be really appreciated as I cant move on until I fix this issue.