How do i fix this error? Cannot implicitly convert type `Sprite' to `UnityEngine.Sprite'
Hi im making my first 2d platformer following a tutorial. i made a healthUI using similar heart system to Zelda hearts.
I finished my script for both player and the health HUD and im getting this error:
Assets/Scripts/HUD.cs(21,25): error CS0029: Cannot implicitly convert type Sprite' to
UnityEngine.Sprite'
this is my code:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class HUD : MonoBehaviour { public Sprite[] HeartSprites;
public Image HeartUI;
public GameObject player;
void Start() { player.GetComponent(); }
void Update() { HeartUI.sprite = HeartSprites [player.GetComponent ().curHealth]; }
}
please help i really want to keep learning
Answer by Chiroculon · Apr 06, 2017 at 02:48 PM
@Maltrane You somehow have two classes named Sprite, and the compiler is getting confused with which is which.
You could be more specific, by replacing:
public Sprite[] HeartSprites;
with
public UnityEngine.Sprite[] HeartSprites;
Your answer
Follow this Question
Related Questions
BCE0044: expecting ''', found '\r'. 1 Answer
Getting weird error message!?!?!? 1 Answer
How do i make my enemies face the player? 2D 0 Answers
Why is my script not working? 1 Answer