unity said that int doesn’t have Length as a variable, but i have been following a video on how to do a health system and he got it to work. If there is something wrong with my code please tell me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour
{
public int health;
public int numOfHearts;
public Image[ ] hearts;
public Sprite heart;
void Start()
{
}
void Update()
{
numOfHearts = Mathf.Clamp(numOfHearts, 1, hearts.Length);
health = Mathf.Clamp(health, 0, numOfHearts);
for (int i = 0; i < health.Length; i++)
{
if (i < health)
{
health*.sprite = heart;*
}
if (i < numOfHearts)
{
hearts*.enabled = true;*
}
else
{
hearts*.enabled = false;*
}
}
}
}