error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are

Your image is broken but I can explain what this error means. In broad terms, there’s a few different types of numbers that a computer works with:

The first broad type is the integer. Integers are counting numbers: 1, 2, 3, -4, etc. When you do math with integers, you will get an integer as a result. This means that 8 / 3 actually equals 2, for example.

The second broad type are floats, or floating point numbers. These can represent numbers with decimals, such as 2.67, or 0.926, to a certain precision. A “double” is also a float. The double moniker comes from being a “double” precision number, using 64 bits whereas normal floats use 32 bits. In C#, floats are marked by ending the number with f, such as 0.2f or 1f. Doubles are demarcated as decimal numbers without any prefix, like 0.2 or 1.0.

Read more about float types here and integer types here.

Since an integer is of lower specificity than floating point, C# doesn’t let you convert a float to an int without doing so explicitly by casting it. Read more about casting here.

Unity operates mainly using floats, so if you want to do any decimal math, you’ll want to get in the habit of suffixing your numbers with the f to designate them as floats, rather than doubles or integers.

If the above does not help, post the context around the code that is not working using code tags , and we will be more able to assist you.

2 Likes