I cannot seem to figure out how to get my script to accept the velocity variable. I’m following an old guide, and it doesn’t tell me how to use the rigidbody.velocity in Unity 5. I’ll put my code below but if you can help could you explain why something goes somewhere? Any help is appreciated, thanks
public class CheekzController : MonoBehaviour {
public float maxSpeed = 11f;
bool facingRight = true;
private Rigidbody2D rigidbody;
// Use this for initialization
void Start () {
rigidbody = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
float move = Input.GetAxis ("Horizontal");
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;
} }