mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-30 21:17:09 +01:00
interactable
This commit is contained in:
@@ -6,15 +6,30 @@ using System;
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
[SerializeField]
|
||||
LayerMask interactableLayer; // Layermask for interactable objects
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Interactable
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit2D hit;
|
||||
|
||||
hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity, interactableLayer);
|
||||
|
||||
if (hit.collider != null)
|
||||
{
|
||||
Interactable interactable = hit.collider.GetComponent<Interactable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.Interact(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user