controller.Move seems to not exist inside the library , probably a minor design flaw in the code sample

Hey everyone!

I have a code sample here made in a test project I was doing, quickly testing stuff with physics and all that. I'm using VS2010, not using .NET. I am using Unity Engine (Of course!) and C# only in this sample.

Here it is:

using UnityEngine;

public class CharacterController : MonoBehaviour   //<----- VERY VERY STUPID
{
    public CharacterController controller;

    // Use this for initialization
    void Start () 
    {
        controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update ()
    {
        float hor = Input.GetAxis("Horizontal");
        float ver = Input.GetAxis("Vertical");
        controller.Move(/*Vector3 info*/);

    }
}

The problem is that the controller object has no Move method. I have the library, the acces modifier is not making any difference so just ignore if it's public private protected or internal for now. I am aware of the sloppy code (Null catching, local typing etc etc. Just ignore that for now please, just want to find why I can not see Move method in the controller)

The controller and script are both hooked to a player object with a rigidbody.

Need more info? Just ask

Thanks in advance

2 Answers

2

The controller object doesn't have a Move method because you didn't write one. You named your class like the already existing type CharacterController, so your controller variable probably references an instance of your own class and not the CharacterController component.

Also you aren't passing a parameter to the Move function and a Move function that takes 0 arguments doesn't exist.

I know, the parameter is not relevant information. What I'm looking for was the move function that was part of the library, but from what I gather, is that there is none at all.

The move method is supposed to be part of the character controller according to the Unity3D example shown here. http://unity3d.com/support/documentation/ScriptReference/CharacterController.Move.html

Yes. And it is. But you are overwriting the CharacterController class. If you rename your class to CharacterController2 it will work.

Ah blast it all, I see it now, what a horrible mistake to name the script CharacterController indeed!

Proper names is a good idea even in rushed testing environments where you just want 1 or 2 things I guess!