Question by
michaelmccarron · May 22, 2017 at 08:59 AM ·
2d animation2dmovement
rigidbody2d.velocity missing assembly reference?
I'm following an older live training session regarding animations playing with movement and I've copied the script exactly, however I get an error. The error is, "UnityEngineComponent does not contain a definition for 'velocity' and no extension method 'velocity' could be found. Are you missing an assembly reference?" This is the code with the error
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
I think it may be to do with it being an older tutorial, is there an updated solution??
I'll add the entire script.
using UnityEngine; using System.Collections;
public class characterMovementScript: MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
}
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 &&!facingRight)
Flip ();
else if(move < 0 && facingRight)
Flip ();
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment