I was following a tutorial from 2018. I typed in the code just like they did and got an error CS1061. It says that ‘Rigidbody 2D’ does not contain an accessible extension method of ‘velocity’ accepting a first argument of type ‘Rigidbody2D’ could be found.Then it asks, are you missing a using directive or an assembly reference?
Is there a way of fixing this?
Show your code and we can help you.
Please use code tags: Using code tags properly
How to report problems productively in the Unity3D forums:
http://plbm.com/?p=220
Help us to help you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movinghat : MonoBehaviour
{
private Rigidbody2D mybody;
public float speed;
void Start()
{
mybody = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
if (h > 0)
{
mybody.velocity = Vector2.right * speed;
}
else if (h < 0)
{
mybody.Velocity = Vector2.left * speed;
}
else
{
mybody.velocity = Vector2.zero;
}
}
}
You used a capital V on one of those. Capitalization matters.
3 Likes