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);
}
}
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:
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)
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.
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.