- Home /
Question by
niazniz · Apr 07, 2016 at 12:53 AM ·
unity 5spritenull reference exception
Trying to create health hearts sprites but error comes
NullReferenceException: Object reference not set to an instance of an object HUD.Update () (at Assets/Scripts/HUD.cs:23)
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class HUD : MonoBehaviour {
public Sprite [] HeartSprites;
public Image HeartUI;
private Player player;
void Start ()
{
player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Player> ();
}
void Update()
{
HeartUI.sprite = HeartSprites[player.curHealth];
}
}
Please HELP!!
Comment
Your answer
Follow this Question
Related Questions
How can I change the sprite using an image URL? 1 Answer
World canvas sprite transform script 1 Answer
How to match UI Image size with sprite size at runtime? 2 Answers
png file's inspector is blank! 0 Answers
Creating Color Scopes in Unity. 1 Answer