0 votes
by (8.2k points)
edited by

I got error - Assets\Scripts\PlayerController.cs(13,44): error CS0246: The type or namespace name 'characterController' could not be found (are you missing a using directive or an assembly reference? I have read all the example scripts and they do not reference a component within the game. The script I am trying to run references the component 'character controller' and errors when trying to test the movement on a character in the game.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{

charactercontroller charactercontroller;
public float MovementSpeed = 5;
public float gravity = 9.8f;
float yMovement;
void Start() 
{
charactercontroller = GetComponent<CharacterController>();
}
void Update()

float horizontal = Input.GetAxis("Horizontal") * MovementSpeed;
float vertical = Input.GetAxis("Vertical") * MovementSpeed;
charactercontroller.Move(transform.forward * vertical + transform.right * horizontal);
if(charactercontroller.isGrounded)
{
 yMovement = 0;
}
else
{
yMovement -= gravity;
charactercontroller.Move(new Vector3(0, yMovement, 0));
}
}
}

ago by
Due to the lack of an accurate and robust method to measure Mg status in patients, the biochemical measurements should always be supported by a clinical assessment of patients at risk for Mg deficiency for timely and proper diagnosis and treatment <a href=https://fastpriligy.top/>priligy where to buy</a> Chakraborty, J

1 Answer

0 votes
by (8.2k points)

A type or namespace that is used in the program was not found. You might have forgotten to reference (References) the assembly that contains the type, or you might not have added the required using directive. Or, there might be an issue with the assembly you are trying to reference.

Check "Character Controller". in line number 13.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

    CharacterController charactercontroller;

    public float MovementSpeed = 5;

    public float gravity = 9.8f;

    float yMovement;

    // Start is called before the first frame update

    void Start()

    {

        charactercontroller = GetComponent<CharacterController>();

    }

    // Update is called once per frame

    void Update()

    {

        float horizontal = Input.GetAxis("Horizontal") * MovementSpeed;

        float vertical = Input.GetAxis("Vertical") * MovementSpeed;

        charactercontroller.Move(transform.forward * vertical + transform.right * horizontal);

        if(charactercontroller.isGrounded)

        {

            yMovement = 0;

        }

        else

        {

            yMovement -= gravity;

            charactercontroller.Move(new Vector3(0, yMovement, 0));

        }

    }

}

TechXR runs courses in AR / VR / Metaverse / Game Development. Some of the popular Q&A in our courses are available here for easy discovery.

113 questions

117 answers

52 comments

105k users

...