fillAmount isn't being recognized by VSC

Hi, I literally started coding yesterday, and I’m following a guide on how to create an enemy with health bars. Here is the code I wrote

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class Enemy : MonoBehaviour
{
  public int curHp;
  public int maxHp;
  public int goldToGive;
  public Image HealthbarFill;
 
  public void Damage ()
  {
      curHp--;
      HealthbarFill.fillamount =  (float)curHp / (float)maxHp;
     
      if(curHp <=0)
      {
         Defeated();
      }
  }
  public void Defeated ()
  {
    Debug.Log("Defeated");
  }
}

In the guide he can post this onto unity with no problem, but when I do it VSC can’t find FillAmount to save its life. I made sure the health bar was on filled and everything, what am I doing wrong

Welcome to it! We’ll get you sorted out.

This one is actually kind of annoying.

Visual Studio has probably suggested you add this:

Visual Studio is wrong.

You want to add this:

using UnityEngine.UI;

That should fix it. If it does not it is because you don’t have UI installed yet and it is a package now.

UnityEngine.UI is now a package:

https://discussions.unity.com/t/846906/2

If Visual Studio is STILL being precious, try these steps to slap it upside the head:

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

https://discussions.unity.com/t/778503

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: https://discussions.unity.com/t/805330/7

1 Like

Hi there! So the thing was I was using an old version of unity’s editor… And once I updated it, problem solved!
I wanna thank you for helping out as quickly as you did, I’m glad I will be able to get help quick when the inevitable mistake comes from me again!

1 Like