Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AnimHandeler : MonoBehaviour
- {
- PlayerManager playerManager;
- public Animator anim;
- InputHandeler inputHandler;
- PlayerMovement playerMovement;
- int vertical;
- int horizontal;
- public bool canRotate;
- public void Initialize()
- {
- playerManager = GetComponentInParent<PlayerManager>();
- anim = GetComponent<Animator>();
- inputHandler = GetComponentInParent<InputHandeler>();
- playerMovement = GetComponentInParent<PlayerMovement>();
- vertical = Animator.StringToHash("Vertical");
- horizontal = Animator.StringToHash("Horizontal");
- }
- public void attack1()
- {
- anim.SetTrigger(AnimTags.attack1Trigger);
- }
- public void attack2()
- {
- anim.SetTrigger(AnimTags.attack2Trigger);
- }
- public void attack3()
- {
- anim.SetTrigger(AnimTags.attack3Trigger);
- }
- public void HeavyAttack1()
- {
- anim.SetTrigger(AnimTags.Heavyattack1Trigger);
- }
- public void HeavyAttack2()
- {
- anim.SetTrigger(AnimTags.Heavyattack2Trigger);
- }
- public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement, bool isSprinting)
- {
- #region Vertical
- float v = 0;
- if (verticalMovement > 0 && verticalMovement < 0.55f)
- {
- v = 0.5f;
- }
- else if (verticalMovement > 0.55f)
- {
- v = 1;
- }
- else if (verticalMovement < 0 && verticalMovement > -0.55f)
- {
- v = -0.5f;
- }
- else if (verticalMovement < -0.55f)
- {
- v = -1;
- }
- else
- {
- v = 0;
- }
- #endregion
- #region Horizontal
- float h = 0;
- if (horizontalMovement > 0 && horizontalMovement < 0.55f)
- {
- h = 0.5f;
- }
- else if (horizontalMovement > 0.55f)
- {
- h = 1;
- }
- else if (horizontalMovement < 0 && horizontalMovement > -0.55f)
- {
- h = -0.5f;
- }
- else if (horizontalMovement < -0.55f)
- {
- h = -1;
- }
- else
- {
- h = 0;
- }
- #endregion
- if(isSprinting)
- {
- v = 2;
- h = horizontalMovement;
- }
- anim.SetFloat(vertical, v, 0.1f, Time.deltaTime);
- anim.SetFloat(horizontal, h, 0.1f, Time.deltaTime);
- }
- public void CanRotate()
- {
- canRotate = true;
- }
- public void StopRotation()
- {
- canRotate = false;
- }
- public void PlayTargetAnim(string tarAnim, bool isInteracting)
- {
- anim.applyRootMotion = isInteracting;
- anim.SetBool("IsInteracting", isInteracting);
- anim.CrossFade(tarAnim, 0.2f);
- }
- public void OnAnimatorMove()
- {
- if (playerManager.isInterationg == false) return;
- float delta = Time.deltaTime;
- playerMovement.rigidbody.drag = 0;
- Vector3 deltaPos = anim.deltaPosition;
- deltaPos.y = 0;
- Vector3 velocity = deltaPos / delta;
- playerMovement.rigidbody.velocity = velocity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement