- Home /
Question by
Quillx · Dec 14, 2020 at 07:17 PM ·
2d-platformer2d sprites2d animation
How come my Attack animation won't work?
Here's my script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
}
else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
if (Input.GetKeyDown("s"))
{
animator.SetBool("Attack", true);
}
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
In theory, with this linked up to any state in the animator, it should work, only my attack animation won't work. But at the same time, my jump animation works, so I dont know what to do. I did get rid of the jump animation though, cuz it looked a little funky. But hopefully someone could tell me why my attack animation isn't working?
Comment
Your answer
Follow this Question
Related Questions
,Spawning snow or changing tilesets to snow as the player walks past them 0 Answers
2D Sprite Fillup without using UI 1 Answer
2D Animation workflow 0 Answers
Jump Animation 2D problems 0 Answers
2d character not flipping ,2D animation not Flipping. HELP 2 Answers