UnityEngineComponent Velocity Error How do I fix it?
UnityEngineComponent Velocity Error How do I fix it?
I am very new to unity and I am getting this error.
I really have no clue what to do to fix it so I hope someone can help me.
UnityEngine.Component' does not contain a definition for velocity' and no extension method
velocity' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?'
velocity' and no extension method
using UnityEngine;
namespace UnitySampleAssets._2D
public class PlatformerCharacter2D : MonoBehaviour
private bool facingRight = true; // For determining which way the player is currently facing.
[SerializeField] private float maxSpeed = 10f; // The fastest the player can travel in the x axis.
[SerializeField] private float jumpForce = 400f; // Amount of force added when the player jumps.
[Range(0, 1)] [SerializeField] private float crouchSpeed = .36f;
// Amount of maxSpeed applied to crouching movement. 1 = 100%
[SerializeField] private bool airControl = false; // Whether or not a player can steer while jumping;
[SerializeField] private LayerMask whatIsGround; // A mask determining what is ground to the character
private Transform groundCheck; // A position marking where to check if the player is grounded.
private float groundedRadius = .2f; // Radius of the overlap circle to determine if grounded
private bool grounded = false; // Whether or not the player is grounded.
private Transform ceilingCheck; // A position marking where to check for ceilings
private float ceilingRadius = .01f; // Radius of the overlap circle to determine if the player can stand up
private Animator anim; // Reference to the player's animator component.
private void Awake()
// Setting up references.
groundCheck = transform.Find("GroundCheck");
ceilingCheck = transform.Find("CeilingCheck");
anim = GetComponent<Animator>();
private void FixedUpdate()
// The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, whatIsGround);
anim.SetBool("Ground", grounded);
// Set the vertical animation
anim.SetFloat("vSpeed", rigidbody2D.velocity.y);
public void Move(float move, bool crouch, bool jump)
// If crouching, check to see if the character can stand up
if (!crouch && anim.GetBool("Crouch"))
// If the character has a ceiling preventing them from standing up, keep them crouching
if (Physics2D.OverlapCircle(ceilingCheck.position, ceilingRadius, whatIsGround))
crouch = true;
// Set whether or not the character is crouching in the animator
anim.SetBool("Crouch", crouch);
//only control the player if grounded or airControl is turned on
if (grounded
private void Flip()
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.