Error Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly con

Welcome! In this forum, you will get much more help if you format your code with code tags <= LINK.

Your error message actually tells you what the problem is, and how to fix it. Let’s break it down.

First, it tells you where the problem is:

Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type

It’s happening at Line 12, Column 49. Here’s Line 12:

[SerializeField] private float _mouseXToY = 1.25;

It tells you what is causing the trouble:

Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type

A “literal” is a constant, like a number, character, or string. In this case, it’s a number:

[SerializeField] private float _mouseXToY = 1.25;

The error message tells you what’s wrong with the number:

Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type

All literal numbers with decimal points in them are initially assumed by C# to be doubles:

[SerializeField] private float _mouseXToY = 1.25; // 1.25 has a decimal, so C# thinks it is a double.

What you are trying to do with the number that is causing the problem:

Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type

You are trying to assign it to a float, which C# does not know how to do:

[SerializeField] private float _mouseXToY = 1.25;

But the error message tells you how to fix it:

Assets\PlayerMovement.cs(12,49): error CS0664: Literal of type double cannot be implicitly converted to type ‘float’; use an ‘F’ suffix to create a literal of this type

So just do what it says:

[SerializeField] private float _mouseXToY = 1.25f;

That makes the literal into a float, and that will solve your problem.

3 Likes