0 votes
by (8.2k points)
edited by

I was trying to build a city tour project given in our course but I found some error please help me find the solution.

Assets\scripts\playerControler.cs(5,5): error CS0246: The type or namespace name'charactercontroller' could not be found (are you missing a using directive or an assembly reference 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerController : MonoBehaviour
{
    charactercontroller characterController;
    public float MovementSpeed = 1;
    public float Gravity = 9.8f;
    private float velocity = 0;
 
    private void Start()
    {
        characterController = GetComponent<CharacterController>();
    }
 
    void Update()
    {
        // player movement - forward, backward, left, right
        float horizontal = Input.GetAxis("Horizontal") * MovementSpeed;
        float vertical = Input.GetAxis("Vertical") * MovementSpeed;
        characterController.Move((transform.right * horizontal + transform.forward *
vertical) * Time.deltaTime);
 
        // Gravity
        if (characterController.isGrounded)
        {
            velocity = 0;
        }
        else
        {
            velocity -= Gravity * Time.deltaTime;
            characterController.Move(new Vector3(0, velocity, 0));
        }
    }
}

1 Answer

0 votes
by (8.2k points)

You have entered "charactercontroller" instead of "CharacterController" in the Script.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

    CharacterController characterController;

    public float MovementSpeed = 1;

    public float Gravity = 9.8f;

    private float velocity = 0;

    private void Start()

    {

        characterController = GetComponent<CharacterController>();

    }

    void Update()

    {

        // player movement - forward, backward, left, right

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

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

        characterController.Move((transform.right * horizontal +

transform.forward * vertical) * Time.deltaTime);

        // Gravity

        if (characterController.isGrounded)

        {

            velocity = 0;

        }

        else

        {

            velocity -= Gravity * Time.deltaTime;

            characterController.Move(new Vector3(0, velocity, 0));

        }

    }

}

Please correct your script.

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

8 comments

99.7k users

...