Added Animations. Changed inspector view for navpoints. A lot of fixes. Changed project structure.
This commit is contained in:
94
Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs
Normal file
94
Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Animators.Leonid_Animator
|
||||
{
|
||||
public class AnimatorHandler : MonoBehaviour
|
||||
{
|
||||
public Animator anim;
|
||||
public bool canRotate;
|
||||
|
||||
private int _horizontal;
|
||||
private int _vertical;
|
||||
private bool _isCrouching = false;
|
||||
private bool _isJumping;
|
||||
|
||||
private int _crouch;
|
||||
private int _jump;
|
||||
private int _fired;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
_vertical = Animator.StringToHash(nameof(_vertical));
|
||||
_horizontal = Animator.StringToHash(nameof(_horizontal));
|
||||
_crouch = Animator.StringToHash(nameof(_crouch));
|
||||
_jump = Animator.StringToHash(nameof(_jump));
|
||||
_fired = Animator.StringToHash(nameof(_fired));
|
||||
}
|
||||
|
||||
public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement,
|
||||
bool pressedJumped, bool pressedCrouching, bool firePressed)
|
||||
{
|
||||
#region Vertical Movement
|
||||
|
||||
var vertical = 0f;
|
||||
if (verticalMovement > 0 && verticalMovement < 0.55)
|
||||
vertical = 0.5f;
|
||||
else if (verticalMovement > 0.55)
|
||||
vertical = 1;
|
||||
else if (verticalMovement < 0 && verticalMovement > -0.55)
|
||||
{
|
||||
vertical = -0.5f;
|
||||
}
|
||||
else if (verticalMovement < -0.55)
|
||||
{
|
||||
vertical = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertical = 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Vertical Movement
|
||||
|
||||
var horizontal = 0f;
|
||||
if (horizontalMovement > 0 && horizontalMovement < 0.55)
|
||||
horizontal = 0.5f;
|
||||
else if (horizontalMovement > 0.55)
|
||||
horizontal = 1;
|
||||
else if (horizontalMovement < 0 && horizontalMovement > -0.55)
|
||||
{
|
||||
horizontal = -0.5f;
|
||||
}
|
||||
else if (horizontalMovement < -0.55)
|
||||
{
|
||||
horizontal = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
horizontal = 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
anim.SetFloat(_horizontal, horizontal, 0.1f, Time.deltaTime);
|
||||
anim.SetFloat(_vertical, vertical, 0.1f, Time.deltaTime);
|
||||
|
||||
if (pressedCrouching == true)
|
||||
{
|
||||
_isCrouching = !_isCrouching;
|
||||
if (_isCrouching == true)
|
||||
transform.Rotate(Vector3.up, 45);
|
||||
else
|
||||
{
|
||||
transform.Rotate(Vector3.up, -45);
|
||||
}
|
||||
anim.SetBool(_crouch, _isCrouching);
|
||||
}
|
||||
|
||||
anim.SetBool(_jump, pressedJumped);
|
||||
anim.SetBool(_fired, firePressed);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user