Player Controller, The character don't move when I insert my animations
Hi, I'm working on my first game for my school project and I have a problem that I can't solve (It's a 2D Game). I have a PlayerController script, that work, but, when I put the animation things the player don't move anymore. When I disable the animator that work again.
Script: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { public float speed; public float jumpForce; private float moveInput; private Rigidbody2D rb; private bool facingRight = true;
private bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumping;
private Animator anim;
void Start(){
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate(){
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space)){
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up*jumpForce;
anim.SetTrigger("TakeOff");
}
if(Input.GetKey(KeyCode.Space)){
if(jumpTimeCounter>0){
rb.velocity = Vector2.up*jumpForce;
jumpTimeCounter -= Time.deltaTime;
anim.SetBool("isJumping", true);
}
else{
isJumping = false;
anim.SetBool("isJumping", false);
}
}
if(Input.GetKeyUp(KeyCode.Space)){
isJumping = false;
anim.SetBool("isJumping", false);
}
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(moveInput == 0){
anim.SetBool("isRunning", false);
}
else{
anim.SetBool("isRunning", true);
}
if(moveInput<0){
transform.eulerAngles = new Vector3(0,180,0);
}
else if(moveInput>0){
transform.eulerAngles = new Vector3(0,0,0);
}
}
I don't know anythings about C#, so if you could be clear in the explanation that would be helpfull. (I'm french so, sorry for my English)
Your answer
Follow this Question
Related Questions
How to Apply Animation to Player 0 Answers
RuntimeAnimatorController not loading from script 4 Answers
How can i draw line with LineRenderer 0 Answers
Needs script trigger animation? 1 Answer
How to check if animation is playing in a Blend Tree? 1 Answer