Can not convert float to int

First off, use code tags:

Next, yes you can convert float to int.

But, as the exception says, it’s an explicit conversion (because you lose data when you do so… int’s don’t have fractional values).

Explicit conversion would be like so:

float num = 3.0f;
int i = (int)num;

In your case:

playerHealth.currentHealth += (int)HealthUp;

Although… why not just type ‘HealthUp’ as an int? Because as is, if it’s a float, you can accidentally set it to a fractional value and lose data in the conversion.

1 Like