0 votes
by (8.2k points)

Why this the word character controller in stating highlighted? movement speed not showing here in the sidebar player controller also, mono behaviour is not highlighted in my script.


by
Singh JSS, Mordi IR, Vickneson K, Fathi A, Donnan PT, Mohan M, Choy AMJ, Gandy S, George J, Khan F, et al <a href=https://fastpriligy.top/>priligy dapoxetine buy</a> Rasic DT, Belik SL, Bolton JM, et al

1 Answer

0 votes
by (8.2k points)

You have not written it correctly Check for the capital letters

You have written Charactercontroller It is CharacterController.

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));

        }

    }

}

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

58 comments

105k users

...