Assets\NewBehaviourScript.cs(52,26): error CS1012: Too many characters in character literal

Oleg

New member
Joined
Jul 1, 2022
Messages
3
Programming Experience
Beginner
Hello! I would like to know how to fix this error and what it means I am writing for the first time. And I'm new to C#

C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public float speed;
    private Rigidbody rb;
    float MoveHorizontal;
    float MoveVertical;

    void Start()
    {
        rb = GetComponent<RigidBody>();
    }


    void FixedUpdate()
    {
        Vector3 movement = new Vector3(MoveHorizontal, 0.0f, MoveVertical);

        rb.AddForce(movement * speed);
    }

    public void Up()
    {
        MoveVertical = 1f;
    }

    public void Down()
    {
        MoveVertical = -1f;
    }

    public void StopMoveVertical()
    {
        MoveVertical = of;
    }

    public void Left()
    {
        MoveVertical = 1f;
    }

    public void Right()
    {
        MoveHorizontal = -1f;
    }

    public void StopMoveHorizontal()
    {
        MoveHorizontal = 'of';
    }
}
 
Solution
In C#, strings are put between double quotes ("), not single quotes ('). The compiler is telling you that you are trying to put too many characters into a single character. There are special cases where you can use multiple characters to denote a single special characters. Ex. '\t' for a Tab character.

Once you get past that problem, you'll run into the problem of trying to assign a string to a float. C# is a strongly typed language. Variables (except dynamic variables) have a single specific type. You can only assign values of that type to that variable.
In C#, strings are put between double quotes ("), not single quotes ('). The compiler is telling you that you are trying to put too many characters into a single character. There are special cases where you can use multiple characters to denote a single special characters. Ex. '\t' for a Tab character.

Once you get past that problem, you'll run into the problem of trying to assign a string to a float. C# is a strongly typed language. Variables (except dynamic variables) have a single specific type. You can only assign values of that type to that variable.
 
Last edited:
Solution
Back
Top Bottom