Godot Version
4.6
Question
I’ve been getting an error saying “Cannot insatiate C# script because the associated class could be not be found. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly.”
I pretty much just used the basic character movement template and changed only the UI actions. The file name is called mc.cs and the class is also called mc so I’m confused. Can anyone help me how to fix this??
using Godot;
using System;
public partial class mc : CharacterBody2D
{
public const float Speed = 300.0f;
public const float JumpVelocity = -400.0f;
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
{
velocity += GetGravity() * (float)delta;
}
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
{
velocity.Y = JumpVelocity;
}
// Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions.
Vector2 direction = Input.GetVector("move_left", "move_right");
if (direction != Vector2.Zero)
{
velocity.X = direction.X * Speed;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
}
Velocity = velocity;
MoveAndSlide();
}
}