'Are you missing a using directive or an assembly reference?'

Viewed 34

I keep getting the error 'The type or namespace 'MovementValue' could not be found - are you missing a using directive or an assembly reference' with the following code:

Would anybody be able to give me a helping hand as to what I am doing wrong (this is my first ever C# script)?

I would be so grateful!

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



public class playercontroller : MonoBehaviour
{

                private Rigidbody rb;
                private float movementX;
                private float movementY;

                void Start()
                {

                    rb = GetComponent<Rigidbody>();

                }


                void OnMove(InputValue movementValue)
                {

                    Vector2 movementValue = movementValue.Get<Vector2>();
                    movementX = movementVector.X;
                    movementY = movementVector.Y;

                }

                void FixedUpdate()
                {

                    Vector3 movement = new Vector3(movementX, 0.0f, movementY);
                    rb.AddForce(movement);

                }
}
1 Answers

Check your cases in the class types:

You declare a private Rigidbody rb; which would be an instance of the type Rigidbody, but on this line - rb = GetComponent<RigidBody>();, you're looking for components of type RigidBody.

The case is significant in C#, and as such, RigidBody (capital B) and Rigidbody (lower case b) are not the same.

On the Unity API reference, the class is named Rigidbody with a lower case b. Changing your code to match should resolve that error.

Related