Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help

Discussion in 'Scripting' started by Rubi-the-Rookie, Aug 12, 2020.

  1. Rubi-the-Rookie

    Rubi-the-Rookie

    Joined:
    Aug 12, 2020
    Posts:
    4
    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?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,138
    Show your code and we can help you.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
  4. Rubi-the-Rookie

    Rubi-the-Rookie

    Joined:
    Aug 12, 2020
    Posts:
    4
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movinghat : MonoBehaviour
    6. {
    7.     private Rigidbody2D mybody;
    8.  
    9.     public float speed;
    10.  
    11.     void Start()
    12.     {
    13.         mybody = GetComponent<Rigidbody2D>();
    14.  
    15.     }
    16.  
    17.  
    18.     void FixedUpdate()
    19.     {
    20.         float h = Input.GetAxis("Horizontal");
    21.         if (h > 0)
    22.         {
    23.             mybody.velocity = Vector2.right * speed;
    24.         }
    25.         else if (h < 0)
    26.         {
    27.             mybody.Velocity = Vector2.left * speed;
    28.         }
    29.         else
    30.         {
    31.             mybody.velocity = Vector2.zero;
    32.         }
    33.     }
    34.  
    35. }
    36.  
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,735
    You used a capital V on one of those. Capitalization matters.
     
  6. Rubi-the-Rookie

    Rubi-the-Rookie

    Joined:
    Aug 12, 2020
    Posts:
    4
    Thank you