Im following a tutorial on creating a healthbar "
". After having created it like at 7:17 my “fill”, “border” and “heart” objects turn invisble and become “script” instead of staying “image” like in the video when he creates the script HealthBar and references it in “Player”.
Have searched for a solution but haven’t found anything. I also get the errors:
The referenced script on this Behaviour (Game Object ‘Border’) is missing!
The referenced script on this Behaviour (Game Object ‘Fill’) is missing!
The referenced script on this Behaviour (Game Object ‘Heart’) is missing!
My code:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private Slider healthSlider;
private int startingHealth = 5;
private int currentHealth = 0;
public void TakeDamage(int damageAmount) {
currentHealth -= damageAmount;
UpdateHealthBar();
if(currentHealth <= 0) {
//Respawn
Respawn();
}
}
private void Respawn() {
currentHealth = startingHealth;
UpdateHealthBar();
}
private void UpdateHealthBar() {
healthSlider.value = currentHealth;
}
}