- Home /
UI Image has no sprite definition
I was looking for tutorials on how to make a health UI and I found the one by BlackThornProd and followed everything. I kept running into the issue were the hearts[i].sprite = fullHeart (and emptyHeart) wouldn't work. It stated there was no sprite definition for image but after looking online, this is exactly what everyone was doing. I tried a few other ways with no success so any help would be appreciated.
  public void HeartUI()
     {
         //hearts[i].GetComponent<SpriteRenderer>.sprite;
         for (int i = 0; i < hearts.Length; i++)
         {
             if(i < health)
             {
                 hearts[i].sprite = fullHeart;
             }
             else
             {
                 hearts[i].sprite = EmptyHeart;
             }
 
             if(i < maxhealth)
             {
                 hearts[i].SetEnabled(true);
             }
             else 
             {
                 hearts[i].SetEnabled(false);
             }
         }
     }
 
 }
               Comment
              
 
               
              How is defined your hearts array? Are you sure you have using UnityEngine.UI; and not using UnityEngine.UIElements; at the top of your script? 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                