Errors that I do not know solve

This is the problem:

NullReferenceException: Object reference not set to an instance of an object
PlayerShooting.Awake () (at Assets/Script/PlayerShooting.cs:41)
UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
PuntodeDisparo:Update() (at Assets/Script/PuntodeDisparo.cs:31)

and, this is the lines:

PlayerShooting
private void Awake()
{

shootableMask = LayerMask.GetMask(“Shootable”);
gunParticle = GetComponent();
//gunLine = GetComponent();
//gunAudio = GetComponent();
gunLigth = GetComponent();
currentBullet = MaxBullet;
StartCoroutine(ReloadAmmo());
enemyImage.enabled = true;
enemyHealthSlider.gameObject.SetActive(false);
}

PuntodeDisparo
void Update()
{
{
if (Input.GetButton(“Fire1”) && Time.time > nextFire)
{
nextFire = Time.time + fireRate;

Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}

}

}

Please, put your code in code tags . It’s unreadable. And please put the whole scripts here, because for example you have an error regarding enemyImage, but there is no other info about it in your code above.

1 Like

@Nixel2013 Hope you solved your issue. But if you haven’t, to solve NREs (Null Reference Exceptions) you just need to check which line it’s bombing out on, and make sure that a reference is set.

I don’t have the exact line numbers so I’m going to guess the lines that are causing the NRE.

The stack traces complains that something in Awake is causing it (PlayerShooting.Awake () (at Assets/Script/PlayerShooting.cs:41))

I think the two possible offenders are

  • enemyImage.enabled = true;
  • enemyHealthSlider.gameObject.SetActive(false);

I’m assuming these are public variables that you assign in the Editor. Can you check if you have actually set a reference in the Unity editor for enemyImage and enemyHealthSlider?

1 Like