2023-03-14 00:59:59 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class PlayerAnimationController : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private Animator animController;
|
|
|
|
[SerializeField]
|
|
|
|
private string runningParameter;
|
|
|
|
[SerializeField]
|
|
|
|
private string runningSpeedParameter;
|
|
|
|
[SerializeField]
|
|
|
|
private string sideStepSpeedParameter;
|
|
|
|
|
|
|
|
private float runningSpeed;
|
|
|
|
private float sideStepSpeed;
|
|
|
|
|
|
|
|
private bool isRunning;
|
|
|
|
private bool movementInterrupt = false;
|
|
|
|
[SerializeField]
|
|
|
|
private PlayerInteractionHandler interactionHandler;
|
2023-05-12 02:14:49 +02:00
|
|
|
[SerializeField]
|
|
|
|
private PlayerMovementController movement;
|
|
|
|
|
|
|
|
private float verticalAiming = 0;
|
|
|
|
[SerializeField]
|
|
|
|
private Camera hiddenCam;
|
2023-03-14 00:59:59 +01:00
|
|
|
|
|
|
|
public void Animate(Vector2 movement,bool jump,bool isMoving)
|
|
|
|
{
|
|
|
|
animController.SetFloat(runningSpeedParameter, movement.magnitude);
|
|
|
|
animController.SetBool(runningParameter,isMoving);
|
|
|
|
//animController.SetFloat(sideStepSpeedParameter, movement.x);
|
|
|
|
|
|
|
|
}
|
|
|
|
public void Animate(PlayerQuickAnimationType animation)
|
|
|
|
{
|
|
|
|
switch(animation)
|
|
|
|
{
|
|
|
|
case PlayerQuickAnimationType.Grab:
|
|
|
|
print("grabbing...");
|
|
|
|
break;
|
|
|
|
case PlayerQuickAnimationType.Shoot:
|
|
|
|
print("shooting...");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 09:30:43 +02:00
|
|
|
public void Hit(bool isDead)
|
2023-04-04 06:04:34 +02:00
|
|
|
{
|
|
|
|
animController.SetTrigger("WasHit");
|
2023-04-21 09:30:43 +02:00
|
|
|
animController.SetBool("IsDead", isDead);
|
2023-04-04 06:04:34 +02:00
|
|
|
}
|
2023-03-14 00:59:59 +01:00
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
2023-04-03 17:02:11 +02:00
|
|
|
animController.SetBool("HasGun",interactionHandler.GunEnabled);
|
2023-05-12 02:14:49 +02:00
|
|
|
|
|
|
|
if (interactionHandler.GunEnabled&&!interactionHandler.isDead&&movement.AllowRotation)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (hiddenCam.transform.localEulerAngles.x < 90)
|
|
|
|
{
|
|
|
|
//DOWN
|
|
|
|
float target = Mathf.Lerp(animController.GetLayerWeight(3), hiddenCam.transform.localEulerAngles.x / 70f,Time.deltaTime*10f);
|
|
|
|
animController.SetLayerWeight(3, target);
|
|
|
|
animController.SetLayerWeight(2, 0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//UP
|
|
|
|
animController.SetLayerWeight(3, 0);
|
|
|
|
float target = Mathf.Lerp(animController.GetLayerWeight(2), (360f - hiddenCam.transform.localEulerAngles.x) / (360f - 300f),Time.deltaTime*10);
|
|
|
|
animController.SetLayerWeight(2, target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
animController.SetLayerWeight(2, Mathf.Lerp(animController.GetLayerWeight(2),0,Time.deltaTime*10));
|
|
|
|
animController.SetLayerWeight(3, Mathf.Lerp(animController.GetLayerWeight(3), 0, Time.deltaTime*10));
|
|
|
|
}
|
2023-04-04 06:04:34 +02:00
|
|
|
|
|
|
|
//print("carrying:" + interactionHandler.IsCarrying + " running:"+animController.GetBool(runningParameter)+" running speed:" + animController.GetFloat(runningSpeedParameter));
|
2023-03-14 00:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum PlayerAnimationType {Movement,Action}
|
|
|
|
public enum PlayerQuickAnimationType { Grab,Shoot}
|