U
U
Uncle Bogdan2021-03-20 11:16:49
C++ / C#
Uncle Bogdan, 2021-03-20 11:16:49

The CharacterController does not contain a Move definition. What's the catch?

The code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterController : MonoBehaviour
{
    [SerializeField][Range(-3,3)] float Sensitivity;
    [SerializeField] Transform Camera;
    [SerializeField] CharacterController controller;
    float CameraPitch;

    private void Start()
    {
        controller = GetComponent<CharacterController>();
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {
        MouseMoving();
        Moving();
    }

    void MouseMoving()
    {
        Vector2 MouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
        CameraPitch -= MouseDelta.y * Sensitivity;

        Mathf.Clamp(CameraPitch, -90, 90);

        Camera.localEulerAngles = Vector3.right * CameraPitch;
        transform.Rotate(Vector3.up * MouseDelta.x * Sensitivity);
        
    }

    private void Moving()
    {
        Vector2 InputDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        InputDirection.Normalize();

        Vector3 Velosity = transform.forward * InputDirection.y + transform.right * InputDirection.x;
        controller.Move(Velosity * Time.deltaTime); // CharacterController не содержит определение Move
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-03-20
@motkot

Well, you wrote your own CharacterController class. And he really doesn't have Move.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question