Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question UI "Image" turns into "Script"

Discussion in 'Scripting' started by fyuten, Apr 2, 2024.

  1. fyuten

    fyuten

    Joined:
    Apr 1, 2024
    Posts:
    3
    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;
    }
    }
     
  2. dstears

    dstears

    Joined:
    Sep 6, 2021
    Posts:
    158
    Can you share some screenshots of how you have set up your object in the scene?
    Did all of the components show up as Images as expected initially, and then broke after you made some change?

    By the way, here is some info on how to post code properly to the forums: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  3. fyuten

    fyuten

    Joined:
    Apr 1, 2024
    Posts:
    3
    After testing more it doesn't seem to be a problem with any of my scripts. If i create any type of UI Slider and press play it turns invisible and all children "Images" become "Scripts". This happends even if i dont use it for anything.

    Here are 2 pictures before and after pressing play on a completely fresh Slider.


    I tried creating a new project and there i succeded, no idea why.
     

    Attached Files:

  4. dstears

    dstears

    Joined:
    Sep 6, 2021
    Posts:
    158
    Does this happen even if you make a new blank scene that has only the canvas and slider (and EventSystem)?
     
  5. fyuten

    fyuten

    Joined:
    Apr 1, 2024
    Posts:
    3
    Yep. I managed to fix it by adding a raw image component and deleting the script. But im missing some image features.