This question was
closed Jun 14, 2019 at 11:52 AM by
llmm for the following reason:
The question is answered, right answer was accepted
Parameter 'Speed' does not exist and animation doesnt work
,using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
private Rigidbody2D myRigidbody;
public bool grounded;
public LayerMask whatIsGround;
private Collider2D myCollider;
private Animator myAnimator;
void Start () {
myRigidbody = GetComponent<Rigidbody2D>();
myCollider = GetComponent<Collider2D>();
myAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
{
if (grounded)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
}
}
myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
myAnimator.SetBool("Grounded", grounded);
}
}
Comment
I think the answer is pretty obvious, you haven't defined the Speed
parameter inside your Animator component.... ($$anonymous$$ake sure the name is Speed
, not speed
nor SPEED
)
Follow this Question
Related Questions
animation play backwards (speed -1) 0 Answers
Change animation speed in animator in child of prefab 1 Answer
How to set the speed to 0 1 Answer