N
N
NoobNoob22021-08-15 14:32:58
C++ / C#
NoobNoob2, 2021-08-15 14:32:58

Vector does not exist in the current context

I wrote one of the scripts responsible for the movement and here is this:
6118fb34c7e5d273107314.png
Here is the code:

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

public class PlayerMotor : BaseMotor
{
    protected override void UpdateMotor()
    {

        MoveVector = InputDirection();


        Move();
    }

    private Vector3 InputDirection()
    {
        Vector3 dir = Vector.zero;

        dir.x = Input.GetAxis("Horizontal");
        dir.z = Input.GetAxis("Vertical");

        if (dir.magnitude > 1)
            dir.Normalize();

        return dir;
    }

If necessary, here is the BaseMotor code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class BaseMotor : MonoBehaviour
{
    protected CharacterController controller;
    protected Transform thisTransform;

    private float baseSpeed = 7.0f;
    private float baseGravity = 25.0f;

    public float Speed { get { return baseSpeed; } }
    public float Gravity { get { return baseGravity; } }
    public Vector3 MoveVector{set; get;}

    protected abstract void UpdateMotor();
    

    protected virtual void Start()
    {
        controller = gameObject.AddComponent<CharacterController>();
        thisTransform = transform;
    }

    private void Update()
    {
        UpdateMotor();
    }

    protected virtual void Move()
    {
        controller.Move(MoveVector * Time.deltaTime);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-08-15
@NoobNoob2

Well, there is no Vector class. The error says it. There are Vector2 and Vector3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question