У меня проблема в том что я написал скрипт атаки, но он почему то выполняет анимацию атаки именно при беге персонажа, в чем ошибка?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class character : MonoBehaviour
{
private Rigidbody2D rb;
public float speed = 1.5f;
private Vector2 moveVector;
public float jumpForce = 5.0f;
public bool isGrounded;
public float damage = 5.0f;
private Animator _animator;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.CompareTag("Grounded"))
{
isGrounded = true;
_animator.SetBool("Jump", false);
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.collider.CompareTag("Grounded"))
{
isGrounded = false;
_animator.SetBool("Jump", true);
}
}
private void Update()
{
moveVector = transform.right * Input.GetAxis("Horizontal") * speed;
Attack();
Jump();
Animation();
}
void FixedUpdate()
{
if(moveVector.x!=0f)MoveCharacter();
}
void MoveCharacter()
{
moveVector.y=rb.velocity.y;
rb.velocity = moveVector;
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(transform.up*jumpForce, ForceMode2D.Impulse);
_animator.SetBool("Jump", true);
}
}
void Attack()
{
if(Input.GetKey(KeyCode.E)){
_animator.SetBool("Attack", true);
}
else{
_animator.SetBool("Attack", false);
}
}
void Animation()
{
if (rb.velocity == Vector2.zero)
{
_animator.SetBool(Animator.StringToHash("Run"), false);
}
else
{
_animator.SetBool(Animator.StringToHash("Run"), true);
}
}
}