Hi i am new in c# and unity and i dont know how to fix this error x.x
i realy hope you guys can help and explain me what i did wrong
The Errors
HealthHeartBar Code looks like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthHeartBar : MonoBehaviour
{
public GameObject heartPrefab;
public float health, maxHealth;
List<HealthHeartBar> hearts = new List<HealthHeartBar>();
public void DrawHearts()
{
ClearHearts();
float maxHealthRemainder = playerHealth.maxHealth % 2;
int heartsToMake = (int)((playerHealth.maxHealth / 2) + maxHealthRemainder);
for(int i = 0; i < heartsToMake; i++)
{
CreateEmptyHeart();
}
for(int i = 0; i < hearts.Count; i++)
{
int HeartStatusRemainder = (int)Mathf.Clamp(playerHealth.health - (i*2), 0, 2);
hearts[i].SetHeartImage((HeartStatus)HeartStatusRemainder);
}
}
public void CreateEmptyHeart()
{
GameObject newHeart = Instantiate(heartPrefab);
newHeart.transform.SetParent(transform);
HealthHeart heartComponent = newHeart.GetComponent<HealthHeart>();
heartComponent.SetHeartImage(HeartStatus.Empty);
hearts.Add(heartComponent);
}
public void ClearHearts()
{
foreach(Transform t in transform)
{
Destroy(t.gameObject);
}
hearts = new List<HealthHeart>();
}
}
and my HealthHeart looks like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthHeart : MonoBehaviour
{
public Sprite fullHeart, halfHeart, emptyHeart;
Image heartImage;
private void Awake()
{
heartImage = GetComponent<Image>();
}
public void SetHeartImage(HeartStatus status)
{
switch (status)
{
case HeartStatus.Empty:
heartImage.sprite = emptyHeart;
break;
case HeartStatus.Half:
heartImage.sprite = halfHeart;
break;
case HeartStatus.Full:
heartImage .sprite = fullHeart;
break;
}
}
}
public enum HeartStatus
{
Empty = 0,
Half = 1,
Full = 2,
}
so where is my misstake i need realy help.
i watched youtube videos, reddit dont find my misstake -.-
hope you can help me
New contributor
Das Shiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.