Class does not contain a definition for 'Move'. (C#)

I’ve looked at other people with the same issue, and for them it just seems to be mistypes and incorrect names, which I’m assuming it’s the same for me, I just can’t for the life of me find out how to fix this one.

using UnityEngine;
using System.Collections;

public class PlayerMvmnt : MonoBehaviour {
	
	// Reference to Character Controller
	PlayerMvmnt pController2D;
	
	// Controls Movement
	public float walkSpeed = 5;
	public float jumpHeight = 5;
	float takenDamage = 0.2f;
	
	// Controlling movement direction
	Vector3 moveDirection = Vector3.zero;
	float horizontal = 0;
	float vertical = 0;


	// Use this for initialization
	
	void Start () {
		pController2D = GetComponent<PlayerMvmnt> ();
	}
	
	// Update is called once per frame
	void Update () {
		//Player Gravity
		vertical = Input.GetAxis ("Vertical");
		horizontal = Input.GetAxis("Horizontal");
		//Controls Movement
		pController2D.Move(moveDirection * Time.deltaTime);
		horizontal = Input.GetAxis("Horizontal");
		vertical = Input.GetAxis ("Vertical");
		
		if (vertical > 0.01) {
			moveDirection.y = vertical * walkSpeed;
		}
		if (vertical < 0.01) {
			moveDirection.y = vertical * walkSpeed;
		}
		
		if (horizontal > 0.01) {
			moveDirection.x = horizontal * walkSpeed;
		}
		if(horizontal < 0.01) {
			moveDirection.x = horizontal * walkSpeed;
		}
	}
	public IEnumerator TakenDamage(){
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
	
	}
}

There’s no method called Move in your PlayerMvmnt class. Also - why does it get a reference to itself in Start?

public class PlayerMvmnt : MonoBehaviour 
{
	PlayerMvmnt pController2D;

Ok… Reference to an instance of itself?

		pController2D.Move(moveDirection * Time.deltaTime);

Hmm… I can’t find the method named “Move” in the script “PlayerMvmnt”. Can you?

Clarifying post

“Move” is referring to this script:
http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html

For the life of me, I can’t figure out this script though. Where in the world does Move come from?

@Platyy: Again, why is the object referring to itself again in the Start function?

Edit: Ah, I see what you tried to do there. “pController2D” has to be a var type of “CharacterController” and MUST be the “CharacterController” component if I’m reading the Doc correctly. So, it should be:

CharacterController pController2D;

void Start()
    pController2D = GetComponent<CharacterController> ();
}

Although I’m not the best at C# alongside methods, so someone may want to recheck syntax of getting the Component.

This script has worked before, I’m not sure what happened for this to happen.
I make Reference to the class so I can use pController2D in the code.

I’m still very new, sorry for the headaches guys haha.

Edited my post (internet was buggy too, so not sure “when” I did it either). Did you try that?

But you’re already in that instance so there’s no need to store a reference to itself. If there were a Move method (and there isn’t) you could write Move() or this.Move() and it would work fine.

After checking the Doc, it makes sense how he made that mistake. “Move()” is a built in function, actually, apparently. Still not sure where the “CharacterController” component comes from (is it built-in? Do you have to add it?) but Move() acts on the CharacterController itself.

@Platyy: Make sure you try my suggestion(s) (and maybe check if there’s this arbitrary CharacterController component in the inspector if it still doesn’t work. You can always script it to check and require the component, too)

Yeah I did, now I just get this error; error CS0029: Cannot implicitly convert type PController2D' to UnityEngine.CharacterController’

I feel so stupid asking these questions, but is there a way I can create a Move method? So it can work fine?

You can move the CharacterController yourself, using other methods (transforms, forces, etc of your choice).

For that error, make sure you do the first line of code. Change line 7
“PlayerMvmnt pController2D;” to “CharacterController pController2D”.

Basically, you’re changing that variable itself to a CharacterController type (rather than an arbitrary, undefined type PlayerMvmnt)

I did change it to that, that’s what game me that new error.

Try to post your current script now. It may be that you accidentally implicitly defined a type of “PController2D” thjs time. Also, does it give a line number?

Also, will be heading to class soon, so if anyone else wants to pick up here to help out, feel free.

Current script state

using UnityEngine;
using System.Collections;

public class PlayerMvmnt : MonoBehaviour {
	
	// Reference to Character Controller
	CharacterController pController2D;
	
	// Controls Movement
	public float walkSpeed = 5;
	public float jumpHeight = 5;
	float takenDamage = 0.2f;
	
	// Controlling movement direction
	Vector3 moveDirection = Vector3.zero;
	float horizontal = 0;
	float vertical = 0;


	// Use this for initialization
	
	void Start () {
		pController2D = GetComponent<PlayerMvmnt> ();
	}
	
	// Update is called once per frame
	void Update () {
		//Player Gravity
		vertical = Input.GetAxis ("Vertical");
		horizontal = Input.GetAxis("Horizontal");
		//Controls Movement
		pController2D.Move(moveDirection * Time.deltaTime);
		horizontal = Input.GetAxis("Horizontal");
		vertical = Input.GetAxis ("Vertical");
		
		if (vertical > 0.01) {
			moveDirection.y = vertical * walkSpeed;
		}
		if (vertical < 0.01) {
			moveDirection.y = vertical * walkSpeed;
		}
		
		if (horizontal > 0.01) {
			moveDirection.x = horizontal * walkSpeed;
		}
		if(horizontal < 0.01) {
			moveDirection.x = horizontal * walkSpeed;
		}
	}
	public IEnumerator TakenDamage(){
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = false;
		yield return new WaitForSeconds(takenDamage);
		renderer.enabled = true;
		yield return new WaitForSeconds(takenDamage);
	
	}
}

You didn’t change line 23 to the following (copied and pasted from that first post):

void Start()

    pController2D = GetComponent<CharacterController> ();

}

That should solve your issue. Although - I guess I’m not the most confident C# person - I’m not sure why it would give you that exact error. However, in the end, this should fix it. (By the way, I didn’t check the rest of your code to check if you’re doing everything else right, but was checking for the exact error related to Move())

MDragon - you’re making the assumption that he’s trying to call the Move method of an attached CharacterController which he hasn’t actually said.

Platyy - If you are trying to use a CharacterController then line 23 needs to change. If you’re not then you need to write your own Move method in that class. If you don’t know how to do either of those things then I would highly suggest you read some C# literature and then do some Unity tutorials.

Yes, I got it. No more errors. Thanks a bunch guys.