why is this code not working?

i wrote this code:
198372-healthprob.png

and it compiled properly but the heath was supposed to go down every the player’s x position was equal to goomba’s(enemy) x position but it didn’t:
file:///C:/Users/vijay/Videos/Captures/My%20project%20(3)%20-%20SampleScene%20-%20Windows,%20Mac,%20Linux%20-%20Unity%202022.1.9f1_%20_DX11_%202022-08-05%2009-59-34.mp4
how can i fix this?

void Start()
{
health = 5;
}
void Update()
{
if(Player.transform.position.x = Goomba.transform.position.x)
health–;
}

According to your code health = 5 on every frame because of the Update function

int health = 5;
void Update()
{
if(Player.transform.position.x = Goomba.transform.position.x)
health–;
}