Okay, so I’m watching a tutorial with nearly 80k views that told me what to code, but when I run this it says there is no definition for “Move.” I know it wasn’t given one, but the tutorial’s code has no errors for some reason? I triple checked for errors in spelling but there are none and it still doesn’t work. How do I give Move a proper defenition?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
public CharacterController controller;
private Vector3 moveDirection;
// Start is called before the first frame update
void Start() {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update() {
moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0f, Input.GetAxis("Vertical") * moveSpeed);
if (Input.GetButtonDown("Jump")) {
moveDirection.y = jumpForce;
}
controller.Move(moveDirection * Time.deltaTime);
}
}
CharacterController already has a definition for Move: Unity - Scripting API: CharacterController.Move
Would you mind pasting the entire error message, including the line number part?
Here’s the error message:
Assets\CharacterController.cs(33,16): error CS1061: ‘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?)
Oh so… did you make your own script called CharacterController? I was assuming you were using the builtin version from Unity: Unity - Scripting API: CharacterController
Did they make their own custom CharacterController class in the tutorial?
Edit: Duh - just looked at your script. Try renaming your script to something else, because Unity has a CharacterController already and I think you’re probably running into trouble because of that.
I renamed the script but am still getting the error. The tutorial does have a CharacterController class, I copied their code word for word.
Edit: I am also using the built in CharacterController for my Player. I think the problem might be that I am not referring back to it?
You can make sure you’re using Unity’s built in character controller by changing the variable declaration to this:
public UnityEngine.CharacterController controller;
and changing the line in Start to this:
controller = GetComponent<UnityEngine.CharacterController>();
But really you’ll have a much easier time if the names are different. Would you mind sharing which tutorial you’re following?
2 Likes