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()._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.
![alt text][1]
[1]: /storage/temp/192928-sem-titulo.png
I'm Brazilian, I used google translator to send a message, I hope you understood
↧