Need help with updating UI based on object pick ups

Basically I am trying to get the UI text to update based on when the player triggers a object on pickup in this case the player picking up a battery that it updates the total count on the UI at the moment when ever I try to test the game the only error I get is that there is no object reference set to an instance of an object so I do not know what to do.

Thank you if you take your time to help.

Flashlight script: using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com

Please post your code in the forums, it’s much easier to look at in the same spot. Use code tags, which you can read about here: Using code tags properly

Okay, also please explain on which line the error is. That is helpful & useful. That being said, when you get the message you did, something is null. So, you have to look at the line in question and work out which variable is null. If there is more than 1 potentially null variable, you have to test each. Sometimes this is super easy, like you forgot to assign it in the inspector. Other times, it’s that you tried to use GameObject.Find and failed to get it… etc…

I would suggest that for this you drag n drop the reference in the inspector. I believe I see the line of code you’re talking about, but then got confused because you said it works for 1 thing , yet not another (but there is only 1 line of code).

Sorry for not laying it out properly as I am new to the forums of unity, basically what i meant by the UI updating was that it works on another script for the Gun but it does not work on the flashlight script that is connected to actual player itself to allow the ontrigger event, the HUD is connected to the main camera that is on the player aswell.

Hi there, I wasn’t here for a bit. Were you able to get this sorted out?