‘Image[]’ does not contain a definition for ‘Lenght’ and no accessible extension method ‘Lenght’ accepting a first argument of type ‘Image[]’ could be found (are you missing a using directive or an assembly reference?)
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.UI;
public class cntrl : MonoBehaviour
{
public float speed;
private float moveInput;
private Animator anim;
private Rigidbody2D rb;
public bool facingRight = true;
public Joystick joystick;
public float health;
public int numOfHearts;
public Image[] hearts;
public Sprite fullHeart;
public Sprite emptyHeart;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
private void FixedUpdate()
{
if(health > numOfHearts)
{
health = numOfHearts;
}
for (int i = 0; i < hearts.Lenght; i++)
{
if (i < Mathf.RoundToInt(health))
{
hearts[i].sprite = fullHeart;
}
else
{
hearts[i].sprite = emptyHeart;
}
if(i < numOfHearts)
{
hearts[i].enabled = true;
}
else
{
hearts[i].enabled = false;
}
}
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (moveInput == 0)
{
anim.SetBool("IsRunning", false);
}
else
{
anim.SetBool("IsRunning", true);
}
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}