interactable

This commit is contained in:
Janis
2023-03-04 15:53:47 +01:00
parent ae0b21f9e9
commit 5f08865a2b
17 changed files with 506 additions and 357 deletions

View File

@@ -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);
}
}
}
}
}