Advertisement
dronkowitz

ItemPickUp.cs

Nov 4th, 2022 (edited)
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5.  
  6. public class ItemPickUp : MonoBehaviour, IInteractable
  7. {
  8.     public Outline objectOutline;
  9.     public Item itemOnGround;
  10.  
  11.     public bool CanInteract(bool isPlayerInteraction)
  12.     {
  13.         return isPlayerInteraction;
  14.     }
  15.  
  16.     private void Start()
  17.     {
  18.         StopHover();
  19.     }
  20.  
  21.     public void Interact(PlayerMovement player)
  22.     {
  23.         if (player.TryGetComponent(out Inventory playerInventory))
  24.         {
  25.             if (playerInventory.AddToBackPack(itemOnGround))
  26.             {
  27.                 Destroy(gameObject);
  28.             }
  29.             else
  30.             {
  31.                 objectOutline.OutlineColor = Color.red;
  32.             }
  33.         }
  34.     }
  35.  
  36.     public void StartHover()
  37.     {
  38.         objectOutline.enabled = true;
  39.         objectOutline.OutlineColor = itemOnGround.itemColor;
  40.     }
  41.  
  42.     public void StopHover()
  43.     {
  44.         objectOutline.enabled = false;
  45.  
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement