У меня много анимаций в моей 2d игре на единство. Все они работают хорошо, потому что я снимаю флажок «Имеет время выхода» и делаю «Продолжительность транзита» между ними равным 0. Но у меня проблема с анимацией атаки. Это не петля. Если я установлю «Транзитная длительность» на 0, то это не закончится, только если я нажму на что-нибудь. Поэтому я установил «Длительность транзита» до 0,3, но теперь он не работает сразу по клику, как мне нужно.
Rigidbody2D rb;
Animator anim;
float speed = 6f;
public int jump;
private bool IsGrounded;
public Transform groundCheck;
public LayerMask whatIsGround;
private void Start() {
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void Update() {
IsGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.5f, whatIsGround); //Is player on ground
if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f) {
jump = 0;
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_1") == false) {
anim.SetInteger("State", 0);
}
}
if (jump == 3) {
jump = 1;
}
if (Input.GetAxis("Horizontal") < 0) { //Running left
GetComponent<SpriteRenderer>().flipX = true;
if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f) {
anim.SetInteger("State", 1);
}
}
if (Input.GetAxis("Horizontal") > 0) { //Running right
GetComponent<SpriteRenderer>().flipX = false;
if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f) {
anim.SetInteger("State", 1);
}
}
if (rb.velocity.y > 0.01f) { //Animation of falling
anim.SetInteger("State", 2);
}
else if (rb.velocity.y < -0.01f) { //Animation of jumping
anim.SetInteger("State", 3);
}
if (Input.GetKeyDown(KeyCode.UpArrow) && (IsGrounded || jump < 2)) {
jump += 1;
if (jump == 1 || jump == 3) {
anim.SetInteger("State", 5); //Another jumping animation
}
rb.velocity = Vector2.up * 12f;
}
if (Input.GetKeyDown(KeyCode.Z)) { //Attack animation
anim.SetInteger("State", 4);
}
}
```[![My animator][1]][1]
[1]: https://i.stack.imgur.com/GegLW.png
Как я могу заставить его работать сразу?