Что я сдал
This commit is contained in:
1 parent
24b1157026
commit
a5665f0101
2838 files changed
+129953
-1304
No files matched your search
@@ -1,3 +1,9 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Alchemy.Inspector;
|
||||
using Code.Audio;
|
||||
using LitMotion;
|
||||
using LitMotion.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
@@ -5,12 +11,26 @@ namespace Code.Player
|
||||
{
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
private static readonly int OnGround = Animator.StringToHash("OnGround");
|
||||
|
||||
[TabGroup("Movement")]
|
||||
[SerializeField] private Transform[] runPositions = new Transform[3];
|
||||
|
||||
[TabGroup("Movement")]
|
||||
[SerializeField] private float jumpStrength;
|
||||
|
||||
[TabGroup("Movement")]
|
||||
[SerializeField] private float sideSpeed;
|
||||
|
||||
[TabGroup("Movement")]
|
||||
[SerializeField] private LayerMask groundMask;
|
||||
|
||||
private Animator _animator;
|
||||
private Rigidbody _rigidbody;
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
_animator = GetComponentInChildren<Animator>();
|
||||
|
||||
InputSystem.actions.actionMaps[0].actions[0].performed += Jump;
|
||||
InputSystem.actions.actionMaps[0].actions[1].performed += MoveRight;
|
||||
@@ -26,7 +46,10 @@ namespace Code.Player
|
||||
|
||||
private void Jump(InputAction.CallbackContext context)
|
||||
{
|
||||
if(!_onGround) return;
|
||||
|
||||
_rigidbody.AddForce(new(0,jumpStrength,0), ForceMode.Impulse);
|
||||
AudioManager.Instance.PlayJump();
|
||||
}
|
||||
|
||||
private int _currentTarget = 1;
|
||||
@@ -41,9 +64,28 @@ namespace Code.Player
|
||||
ChangePosition();
|
||||
}
|
||||
|
||||
private MotionHandle _sideMotion;
|
||||
private bool _onGround;
|
||||
private Collider[] _overlapResults = new Collider[1];
|
||||
|
||||
private void ChangePosition()
|
||||
{
|
||||
transform.position = runPositions[_currentTarget].position;
|
||||
if(_sideMotion.IsActive()) _sideMotion.Cancel();
|
||||
|
||||
_sideMotion = LMotion
|
||||
.Create(transform.position.x, runPositions[_currentTarget].position.x, sideSpeed)
|
||||
.WithEase(Ease.Linear)
|
||||
.BindToPositionX(transform);
|
||||
// transform.position = runPositions[_currentTarget].position;
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var groundedCheck = Physics.OverlapSphereNonAlloc(transform.position, 1f, _overlapResults, groundMask);
|
||||
|
||||
_onGround = groundedCheck > 0;
|
||||
_animator.SetBool(OnGround, _onGround);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user