Question by
mataveli91 · Feb 21 at 09:09 PM ·
error messagenullreferenceexceptionbugs
MissingReferenceException: The object of type 'Script' has been destroyed but you are still trying to access it.
Oops guys. I know this error is pretty much the most common Unity error... I have been programming in Unity for 2 years and now I have a game project, however, the mechanics of hitting the enemy is not working when he is Instantiated for the 2nd time or when the scene is reloaded. I honestly don't know what to do and I hope your help. Here are some error files.
Attack Box Script (It is activated at a moment of the attack animation)
public sealed class PlayerAttackArea : MonoBehaviour
{
private int _damageValue;
private GameObject objHit;
public delegate void DealDamage(int damage, GameObject obj);
public static event DealDamage OnEnemyHit;
private void Start()
{
this._damageValue = GetComponentInParent<Player>()._damageValue;
}
private void OnTriggerEnter2D(Collider2D other)
{
objHit = other.gameObject;
if (OnEnemyHit != null)
{
OnEnemyHit(_damageValue, objHit);
print("Something Hit");
objHit = null;
} else if (OnEnemyHit == null)
{
print("Event not found");
}
}
}
Function script that is returning an error. Remembering that I'm using events to communicate between scripts.
private void IWasHit(int damageValue, GameObject obj)
{
if (obj == gameObject)
{
print(obj.name+" Foi Acertado");
TakeDamage(damageValue);
}
}
That method in turn asks for another method of a class being inherited. Now finally the error that is returned.
I'm Brazilian, I used google translator to send a message, I hope you understood
sem-titulo.png
(26.3 kB)
Comment