Skip to content
Snippets Groups Projects
InteractCursor.cs 1.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • Josiane Pos's avatar
    Josiane Pos committed
    using System;
    using Interactable;
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    public class InteractCursor : MonoBehaviour
    {
        private IInteractable m_currentInteractable;
        private InputAction m_Interact;
    
    Josiane Pos's avatar
    Josiane Pos committed
        private void Start()
        {
            m_Interact = InputSystem.actions.FindAction("Interact");
        }
    
        private void Update()
        {
    
            if (m_Interact.WasPressedThisFrame())
    
    Josiane Pos's avatar
    Josiane Pos committed
            {
    
                Debug.Log("Interact");
    
    Josiane Pos's avatar
    Josiane Pos committed
                m_currentInteractable?.OnInteract();
            }
        }
    
        private void OnTriggerEnter2D(Collider2D other)
    
    Josiane Pos's avatar
    Josiane Pos committed
        {
            Debug.Log("Enter");
            
            if (other.TryGetComponent(out SpriteRenderer sprite))
            {
                sprite.color = Color.blue;
            }
            if (other.TryGetComponent(out IInteractable interactable))
            {
                m_currentInteractable = interactable;
    
                Debug.Log(m_currentInteractable);
    
        private void OnTriggerExit2D(Collider2D other)
    
    Josiane Pos's avatar
    Josiane Pos committed
        {
            if (other.TryGetComponent(out SpriteRenderer sprite))
            {
                sprite.color = Color.white;
            }
        }
    }