0
I need to assign a decimal to a variable, but I keep getting errors, and float isn't working.(I'm using unity, and visual studio
here's the code: int hp = 100; float shieldPower = 76.5f; int laserDamage = 15; hp -= (laserDamage - shieldPower); Error message: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists(are you missing a cast?)
4 Respostas
+ 2
Please share your code and the errors.
+ 2
the result of statement
hp -= (laserDamage - shieldPower);
is float, and the value must stored in float variable.
but if you want to store it in int, try to cast (use casting) the result, like that:
hp -= (int)(laserDamage - shieldPower);
+ 1
Thank you! I think it's working. I'm really new to C#, so all the help is really appreciated.
0
my code is now in the description