This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract input and animations behaviours from Player script to single different scripts
- Loading branch information
Showing
4 changed files
with
44 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PlayerAnimations : MonoBehaviour | ||
{ | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
|
||
} | ||
[SerializeField] | ||
private Animator playerAnimator; | ||
|
||
// Update is called once per frame | ||
void Update() | ||
public void SetupAnimations(Vector2 movement) | ||
{ | ||
|
||
if (movement.magnitude > 0) | ||
{ | ||
playerAnimator.SetBool("Walk", true); | ||
} | ||
else | ||
{ | ||
playerAnimator.SetBool("Walk", false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System; | ||
using UnityEngine; | ||
|
||
public class PlayerInput : MonoBehaviour | ||
{ | ||
// Start is called before the first frame update | ||
void Start() | ||
public Vector2 MovementInput { get; private set; } | ||
|
||
public event Action OnInteractEvent; | ||
|
||
private void Update() | ||
{ | ||
GetInteractInput(); | ||
GetMovementInput(); | ||
} | ||
|
||
private void GetMovementInput() | ||
{ | ||
|
||
MovementInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); | ||
MovementInput.Normalize(); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
private void GetInteractInput() | ||
{ | ||
|
||
if (Input.GetAxisRaw("Fire1") > 0) | ||
{ | ||
OnInteractEvent?.Invoke(); | ||
} | ||
} | ||
} |