- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CharacterAnimationController : MonoBehaviour
- {
- private Animator animator;
- public float dumpTime = 0.1f;
- private CharacterMovement characterMovement;
- private PlayerController playerController;
- private Health healthScript;
- private float horizontal, vertical;
-
- void Start()
- {
- characterMovement = GetComponent<CharacterMovement>();
- playerController = GetComponent<PlayerController>();
- healthScript = GetComponent<Health>();
- animator = GetComponentInChildren<Animator>();
- }
-
- void Update()
- {
- horizontal = (Input.GetAxis("Horizontal"));
- vertical = (Input.GetAxis("Vertical"));
-
-
- Idle();
- Run();
- Jump();
- Injured();
-
- PushAndPull();
- Dash();
-
- StartCoroutine(Attack());
- StartCoroutine(Parry());
- LooseHealth();
-
-
- SecretDance();
- }
- private void Idle()
- {
- if (horizontal < 0f || vertical < 0f)
- {
- animator.SetFloat("Speed", 0f);
- }
- }
- private void Run()
- {
- if(animator.GetFloat("Speed") != Mathf.Abs(horizontal) + Mathf.Abs(vertical))
- animator.SetFloat("Speed", Mathf.Abs(horizontal) + Mathf.Abs(vertical), dumpTime, Time.deltaTime);
-
- }
- private void Jump()
- {
- if (Input.GetKeyDown(KeyCode.Space) && characterMovement.numberOfJumps < 1)
- {
- animator.SetTrigger("Jump");
- }
- }
-
- private void Dash()
- {
- if (Input.GetKeyDown(playerController.abilities[2].code))
- {
-
-
- animator.SetTrigger("Dash");
- }
- }
- private void PushAndPull()
- {
- if (!playerController.intention)
- {
- if (Input.GetKey(playerController.abilities[3].code) || Input.GetKey(playerController.abilities[4].code))
- {
- animator.SetBool("PushAndPull", true);
- animator.SetLayerWeight(animator.GetLayerIndex("PushAndPull Layer"), 1);
- }
- else
- animator.SetBool("PushAndPull", false);
- }
- }
- private void Injured()
- {
- if (healthScript.hp <= healthScript.totalHealth / 2)
- {
- animator.SetLayerWeight(animator.GetLayerIndex("Injured Layer"), 1);
- }
- else
- animator.SetLayerWeight(animator.GetLayerIndex("Injured Layer"), 0);
- }
- private IEnumerator Parry()
- {
- if (playerController.intention)
- {
- if (Input.GetKeyDown(playerController.abilities[5].code))
- {
-
- animator.SetLayerWeight(animator.GetLayerIndex("Parry Layer"), 1);
- animator.SetTrigger("Parry");
- yield return new WaitForSeconds(0.9f);
- }
- }
- }
- private void LooseHealth()
- {
- if (Input.GetKeyDown("l"))
- {
- healthScript.hp -= 10f;
- }
- if (Input.GetKey("k"))
- {
- healthScript.hp = healthScript.totalHealth;
- }
- }
- private IEnumerator Attack()
- {
- if (playerController.intention)
- {
- if (Input.GetKeyDown(playerController.abilities[0].code))
- {
-
- animator.SetLayerWeight(animator.GetLayerIndex("Attack Layer"), 1);
- animator.SetTrigger("Attack");
- yield return new WaitForSeconds(0.9f);
- }
- }
- }
- private void SecretDance()
- {
- if (Input.GetKeyDown("t"))
- {
- animator.SetTrigger("Dance");
- }
- }
- private void GettingHit()
- {
- }
- }