My game don't wanna start

When I start my game I have this error message:

‘CharacterController’ does not contain a definition for ‘Move’ and no accessible extension method ‘Move’ accepting a first argument of type ‘CharacterController’ could be found (are you missing a using directive or an assembly reference?)

I Don’t know how to fix this, could you help me please?

This is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterController : MonoBehaviour
{
public float speed = 10f;
public float jump = 20f;
private Vector2 DirectionDeplacement = Vector2.zero;
private CharacterController Player;

// Start is called before the first frame update
void Start()
{
Player = GetComponent();
}

// Update is called once per frame
void Update()
{
DirectionDeplacement.x = Input.GetAxisRaw(“Horizontal”);
DirectionDeplacement = transform.TransformDirection(DirectionDeplacement);

Player.Move(DirectionDeplacement * speed * Time.deltaTime);
}
}

1 Like

the script makes no sense for me.

You have script CharacterController. Player is referenced variable for the CharacterController. Then you are making reference from this script to itself (Player = GetComponent();). And later you are trying to execute Move function in the CharacterController but the CharacterController don’t have the function Move.

do you have some other scripts ?

2 Likes

If you’re trying to use Unity’s CharacterController, you probably shouldn’t name your class CharacterController as well, or if you want to, you need to use UnityEngine namespace.

private UnityEngine.CharacterController Player;
and
Player = GetComponent<UnityEngine.CharacterController>();
Otherwise the compiler will think you’re referencing your own class here.

2 Likes

Here’s Unity’s CharacterController class (in the scripting API):

Take a look and see if it has the functionality you need! (It should also be a good learning exercise).

Best of Luck,

Mike
BeinGames Studio

1 Like