game(scripts): merge players

This commit is contained in:
Mark Joshwel 2024-08-11 04:20:08 +08:00
parent 3613b57679
commit f1b5d615c2
3 changed files with 49 additions and 62 deletions

View file

@ -1,35 +0,0 @@
/*
* author: mark joshwel
* date: 27/5/2024
* description: script for handling player interactivity
*/
using UnityEngine;
/// <summary>
/// class for handling player interactivity
/// </summary>
public class MarkPlayer : MonoBehaviour
{
/// <summary>
/// game manager instance
/// </summary>
private GameManager _game;
/// <summary>
/// initialisation function
/// </summary>
private void Start()
{
_game = GameManager.Instance;
}
/// <summary>
/// function called by the input system when escape is paused
/// </summary>
public void OnPause()
{
Debug.Log("escape pressed");
_game.SetDisplayState(_game.Paused ? GameManager.DisplayState.Game : GameManager.DisplayState.OverlayPauseMenu);
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 995d26dc842b43269f0cfd51fe4e32ef
timeCreated: 1723266626

View file

@ -1,53 +1,61 @@
/* /*
* author: ryan lin * author: ryan lin, mark joshwel
* date: 8/8/2024 * date: 11/8/2024
* description: TODO * description: player interaction behaviour
*/ */
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
/// TODO /// player interaction behaviour
/// </summary> /// </summary>
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
/// <summary> /// <summary>
/// TODO /// the position of the player
/// </summary> /// </summary>
[SerializeField] private Transform playerPosition; [SerializeField] private Transform playerPosition;
/// <summary> /// <summary>
/// TODO /// the maximum distance the player can interact with objects
/// </summary> /// </summary>
[SerializeField] private float seeDistance; [SerializeField] private float interactableDistance;
/// <summary> /// <summary>
/// TODO /// the layers the raycast should interact with
/// </summary> /// </summary>
public LayerMask raycastLayers; public LayerMask raycastLayers;
/// <summary> // /// <summary>
/// TODO // /// the current interactable object the player is looking at
/// </summary> // /// </summary>
private bool _active; // private CommonInteractable _currentInteractable;
/// <summary> /// <summary>
/// TODO /// game manager instance
/// </summary> /// </summary>
private CommonInteractable _currentInteractable; private GameManager _game;
/// <summary> /// <summary>
/// TODO /// whether the player is looking at an interactable object
/// </summary> /// </summary>
private bool _raycast; private bool _raycast;
/// <summary> /// <summary>
/// TODO /// the raycast hit information
/// </summary> /// </summary>
public RaycastHit Hit; public RaycastHit Hit;
/// <summary> /// <summary>
/// TODO /// initialisation function
/// </summary>
private void Start()
{
_game = GameManager.Instance;
}
/// <summary>
/// raycast performer for interactable objects
/// </summary> /// </summary>
private void Update() private void Update()
{ {
@ -55,24 +63,41 @@ private void Update()
playerPosition.position, playerPosition.position,
playerPosition.TransformDirection(Vector3.forward), playerPosition.TransformDirection(Vector3.forward),
out Hit, out Hit,
seeDistance, interactableDistance,
raycastLayers raycastLayers
); );
Debug.DrawRay( Debug.DrawRay(
playerPosition.position, playerPosition.position,
playerPosition.TransformDirection(Vector3.forward) * seeDistance, playerPosition.TransformDirection(Vector3.forward) * interactableDistance,
Color.green Color.green
); );
if (!_raycast) return;
// show an interaction prompt if we're looking at an interactable object
var prompt = Hit.collider.GetComponent<CommonInteractable>()?.interactionPrompt;
if (prompt != "")
{
Debug.Log(prompt);
}
} }
/// <summary> /// <summary>
/// TODO /// handles the action when the player interacts with an object
/// </summary> /// </summary>
private void OnAction() private void OnAction()
{ {
Debug.Log("test"); if (!_raycast) return;
if (_raycast) Hit.collider.GetComponent<CommonInteractable>()?.Interact();
if (Hit.transform.CompareTag("Interactable")) // _currentInteractable?.Interact();
Hit.transform.GetComponent<CommonInteractable>().Interact(); }
/// <summary>
/// function called by the input system when escape is paused
/// </summary>
public void OnPause()
{
Debug.Log("escape pressed");
_game.SetDisplayState(_game.Paused ? GameManager.DisplayState.Game : GameManager.DisplayState.OverlayPauseMenu);
} }
} }