Project
This commit is contained in:
1 parent
e1a474d4ac
commit
24b1157026
164 files changed
+68527
No files matched your search
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Player
|
||||
{
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform[] runPositions = new Transform[3];
|
||||
[SerializeField] private float jumpStrength;
|
||||
private Rigidbody _rigidbody;
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
|
||||
InputSystem.actions.actionMaps[0].actions[0].performed += Jump;
|
||||
InputSystem.actions.actionMaps[0].actions[1].performed += MoveRight;
|
||||
InputSystem.actions.actionMaps[0].actions[2].performed += MoveLeft;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
InputSystem.actions.actionMaps[0].actions[0].performed -= Jump;
|
||||
InputSystem.actions.actionMaps[0].actions[1].performed -= MoveRight;
|
||||
InputSystem.actions.actionMaps[0].actions[2].performed -= MoveLeft;
|
||||
}
|
||||
|
||||
private void Jump(InputAction.CallbackContext context)
|
||||
{
|
||||
_rigidbody.AddForce(new(0,jumpStrength,0), ForceMode.Impulse);
|
||||
}
|
||||
|
||||
private int _currentTarget = 1;
|
||||
private void MoveRight(InputAction.CallbackContext context)
|
||||
{
|
||||
if(_currentTarget != 2) _currentTarget++;
|
||||
ChangePosition();
|
||||
}
|
||||
private void MoveLeft(InputAction.CallbackContext context)
|
||||
{
|
||||
if(_currentTarget != 0) _currentTarget--;
|
||||
ChangePosition();
|
||||
}
|
||||
|
||||
private void ChangePosition()
|
||||
{
|
||||
transform.position = runPositions[_currentTarget].position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd850809c4f498280fac867c038af4d
|
||||
timeCreated: 1777827949
|
||||
Reference in new issue
Block a user