So unity is reporting an error that I don’t know how to fix.
The Error is:
NullReferenceException: Object reference not set to an instance of an object
VidaPlayer.OnTriggerStay2D (UnityEngine.Collider2D outro) (at Assets/Scripts/VidaPlayer.cs:33)
Here is the Player Life code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VidaPlayer : MonoBehaviour
{
public bool Vivo = true;
public Image lifeBar;
public int valorAtual = 10;
//public int dano = 1;
public float fireRate = 0.5f;
private float nextAttack;
private LocalDano inimigo;
public GameObject LocalDano;
void Start()
{
inimigo = LocalDano.GetComponent<LocalDano>();
}
void Update()
{
}
void OnTriggerStay2D(Collider2D outro)
{
if(outro.gameObject.CompareTag("DanoInimigo"))
{
if(Time.time > nextAttack && valorAtual > 0)
{
valorAtual -= inimigo.danoInimigo;
lifeBar.fillAmount = (float)valorAtual / 10;
nextAttack = Time.time + fireRate;
}
else if(valorAtual <= 0)
{
Vivo = false;
Destroy(gameObject);
}
}
}
}
Here is the Enemy Damage code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LocalDano : MonoBehaviour
{
//public Transform Inimigo;
//public float vel = 100000.0f;
public int danoInimigo = 1;
void Start()
{
}
// Update is called once per frame
void Update()
{
//transform.position = Vector2.MoveTowards(this.transform.position, Inimigo.transform.position, vel * Time.deltaTime);
}
}
Thank you very much in advance