Question by
erikosyakua · Apr 07, 2017 at 02:46 PM ·
2derrorgames
UnityEngine.Component could be found
Hi everyone. Faced a problem, made a script for the movement of 2d character, but an error occurs " 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? " what am I doing wrong?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CharacterControllerScript : MonoBehaviour { public float maxSpeed = 10f; private bool isFacingRight = true; private Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
}
private void FixedUpdate()
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !isFacingRight)
Flip();
else if (move < 0 && isFacingRight)
Flip();
}
private void Flip()
{
isFacingRight = !isFacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rigibody2d.velocity error? 0 Answers
Referencing another script error/problem 0 Answers
NullReferenceException, Script Error 1 Answer