2 CS0234 errors and 1 CS0246 error

Can u help me ?

First error

Assets\Scripts\LifeSystem.cs(4,19): error CS0234: The type or namespace name ‘UI’ does not exist in the namespace ‘UnityEngine’ (are you missing an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LifeSystem : MonoBehaviour
{
player player;
public bool dead;
public int life;
public int maxLife;

public Image [ ] heart;
public Sprite Full;
public Sprite Empty;

// Start is called before the first frame update
void Start()
{
player = GetComponent();
}

// Update is called once per frame
void Update()
{
HealthLogic();
DeadState();
}

void HealthLogic()
{

if(life > maxLife)
{
life = maxLife;
}

for (int i = 0; i < heart.Length; i++)
{
if(i< life)
{
heart*.sprite = Full;*
}
else
{
heart*.sprite = Empty;*
}
if(i < maxLife)
{
heart*.enabled = true;*
}
else
{
heart*.enabled = false;*
}
}
}
void DeadState()
{
if(life <= 0)
{
dead = true;
player.anim.SetBool(“dead”,dead);
GetComponent().enabled = false;
Destroy(gameObject, 1.0f);
}
}
}
Second Error
Assets\Scripts\PlayerLogic.cs(4,19): error CS0234: The type or namespace name ‘UI’ does not exist in the namespace ‘UnityEngine’ (are you missing an assembly reference?)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class player : MonoBehaviour
{
public float Speed;
public float JumpForce;
public bool isJumping;
public bool doubleJumping;
private Rigidbody2D rig;
public Animator anim;
private Vector3 respawnPoint;
public GameObject fallDetector;
public GameObject shotProject;
public Transform Weapon;
private bool shot;
public float shotForce;
// Start is called before the first frame update
void Start()
{
rig = GetComponent();
anim = GetComponent();
respawnPoint = transform.position;
}
// Update is called once per frame
void Update()
{
Move();
Jump();
fallDetector.transform.position = new Vector2(transform.position.x, fallDetector.transform.position.y);
shot = Input.GetButtonDown(“Fire”);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == “FallDetector”)
{
transform.position = respawnPoint;
}
}
void Move()
{
Vector3 movement = new Vector3(Input.GetAxis(“Horizontal”), 0f, 0f);
transform.position += movement * Time.deltaTime * Speed;

if(Input.GetAxis(“Horizontal”) > 0f)
{
anim.SetBool(“walk”, true);
transform.eulerAngles = new Vector3(0f,0f,0f);
}
if(Input.GetAxis(“Horizontal”) < 0f)
{
anim.SetBool(“walk”, true);
transform.eulerAngles = new Vector3(0f,180f,0f);
}
if(Input.GetAxis(“Horizontal”) == 0f)
{
anim.SetBool(“walk”, false);
}
shot = Input.GetButtonDown(“Fire2”);
}
void Jump()
{
if(Input.GetButtonDown(“Jump”))
{
if (!isJumping)
{
rig.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
doubleJumping = true;
anim.SetBool(“jump”, true);
}
else
{
if(doubleJumping)
{
rig.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
doubleJumping = false;
}
}

}
}
void OnCollisionEnter2D(Collision2D colli)
{
if(colli.gameObject.layer == 8)
{
isJumping = false;
anim.SetBool(“jump”, false);
}
}
void OnCollisionExit2D(Collision2D colli)
{
if(colli.gameObject.layer == 8)
{
isJumping = true;
}
}
private void shooting()
{
if(shot == true)
{
GameObject temp = Instantiate(shotProject);
temp.transform.position = Weapon.position;
temp.GetComponent().velocity = new Vector2(shotForce, 0);
Destroy(temp.gameObject, 3f);
}
}
}
Third Error
Assets\Scripts\LifeSystem.cs(13,12): error CS0246: The type or namespace name ‘Image’ could not be found (are you missing a using directive or an assembly reference?)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LifeSystem : MonoBehaviour
{
player player;
public bool dead;
public int life;
public int maxLife;
public Image [ ] heart;
public Sprite Full;
public Sprite Empty;
// Start is called before the first frame update
void Start()
{
player = GetComponent();
}
// Update is called once per frame
void Update()
{
HealthLogic();
DeadState();
}
void HealthLogic()
{
if(life > maxLife)
{
life = maxLife;
}
for (int i = 0; i < heart.Length; i++)
{
if(i< life)
{
heart*.sprite = Full;*
}
else
{
heart*.sprite = Empty;*
}
if(i < maxLife)
{
heart*.enabled = true;*
}
else
{
heart*.enabled = false;*
}
}
}
void DeadState()
{
if(life <= 0)
{
dead = true;
player.anim.SetBool(“dead”,dead);
GetComponent().enabled = false;
Destroy(gameObject, 1.0f);
}
}
}

Yes, use code tags, here is how: https://discussions.unity.com/t/481379

The usual problem when this appears is an uninstalled Unity UI package (com.unity.ugui).

Since your November post shows you using UnityEngine.UI correctly, this is likely just your editor losing its mind.

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.

Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

Barring all that, move on to other ideas:

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

Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.

Update: The VSCode extension has been deprecated and abandoned:

Update: the VSCode integration is back… maybe!?

There may be a community fork available that is receiving updates.

Also, this: No suggestions in Vscode

Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.

Otherwise, as Lurk correctly points out:

UnityEngine.UI is now a package:

To avoid using the Project Mangler UI, add it directly to your project’s Packages/manifest.json as this line:

"com.unity.ugui": "1.0.0",

Annoying possible issue circa October 2021:

ALSO… get rid of everything you don’t need.

Extra unwanted packages in new projects (collab, testing, rider and other junk):

About the fastest way I have found to make a project and avoid all this noise is to create the project, then as soon as you see the files appear, FORCE-STOP (hard-kill) Unity (with the Activity Manager or Task Manager), then go hand-edit the Packages/manifest.json file as outlined in the above post, then reopen Unity.

Sometimes the package system gets borked from all this unnecessary churn and requires the package cache to be cleared:

https://stackoverflow.com/questions/53145919/unity3d-package-cache-errors/69779122

And finally, for future reference:

How to report your problem productively in the Unity3D forums:

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

  • Do not TALK about code without posting it.
  • Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
  • Do NOT post screenshots of code.
  • Do NOT post photographs of code.
  • Do NOT attach entire scripts to your post.
  • ONLY post the relevant code, and then refer to it in your discussion.