Search Unity

HELP WITH 2D PLATFORMER ERROR

Discussion in 'Scripting' started by Maltrane, Feb 14, 2016.

  1. Maltrane

    Maltrane

    Joined:
    Feb 14, 2016
    Posts:
    2
    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<Player>();
    }


    void Update()
    {
    HeartUI.sprite = HeartSprites [player.GetComponent<Player> ().curHealth];
    }


    }

    please help i really want to keep learning
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Things you need to do
    1. Don't use caps in the titles.
    2. Put your codes into code tags (under insert on the comment toolbar)
    3. Import UnityEngine.Sprite
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Do you maybe have a script named 'Sprite' in your project?