Guapus
Guapus

Reputation: 1

'The type or namespace name could not be found ' how to solve in Unity

I'm trying to setup play movement with a unity script from a you tube video Im watching. currently I'm getting the error

"The type of namespace name 'RigidBody2D' could not be found"

I have a RigidBody2D Attached to my sprite an I'm pretty lost on what to do next. here is my cod any help would be greatly appreciated!

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

    [RequireComponent(typeof(RigidBody2D))]
    // this makes sure if a rigid body doesnt exist in the player it will add one

    public class playermovement : MonoBehaviour
    {
    public RigidBody2D playerRigidBody;
    public float moveSpeed = 1f;


    public void Awake()
    {
      playerRigidBody = GetComponent<RigidBody2D>();
    }

    private void FixedUpdate()
    {
      if(playerRigidBody != null)
      {
          ApplyInput();
      }
      else
      {
        Debug.LogWarning("rigid body not attached to player" +GameObject.name);
      }
    }


    //Chek to see if any buttions are pushed down and if so perform any relivent action

      public void ApplyInput()
    {
    float HorizontalInput = Input.GetAxis("Horizontal");
    float VerticalInput = Input.GetAxis("Vertical");

    float HorizontalForce = HorizontalInput * moveSpeed * Time.deltaTime;


      Vector2 force = new Vector2(HorizontalForce,0);
     playerRigidBody.AddForce(force);


    }
   }

Upvotes: 0

Views: 1132

Answers (1)

Hamid Yusifli
Hamid Yusifli

Reputation: 10137

Replace this class name:

RigidBody2D

with this:

Rigidbody2D

Here is the reference for the Rigidbody2D class.

Upvotes: 1

Related Questions