91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
|
|||
|
namespace SimpleInventorySystem
|
|||
|
{
|
|||
|
[RequireComponent(typeof(Collider), typeof(Inventory))]
|
|||
|
public class Player_IS : MonoBehaviour
|
|||
|
{
|
|||
|
//public bool CanPickupItem { get; private set; }
|
|||
|
//public PickUp storedPickUp;
|
|||
|
public List<PickUp> pickUpsInRange = new List<PickUp>();
|
|||
|
[HideInInspector] public Inventory inventory;
|
|||
|
public List<TargetAttachment> targetAttachments;
|
|||
|
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public bool AttachItemGameObject(GameObject go, ItemTags itemTag, ItemUI itemUI)
|
|||
|
{
|
|||
|
foreach (TargetAttachment ta in targetAttachments)
|
|||
|
{
|
|||
|
if(ta != null && ta.AttachItemGameObject(go, itemTag, itemUI.pickUp))
|
|||
|
{
|
|||
|
itemUI.targetAttachment = ta;
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void DetachItemGameObject(GameObject go, ItemUI itemUI)
|
|||
|
{
|
|||
|
itemUI.targetAttachment.DetachItemGameObject(go);
|
|||
|
itemUI.pickUp.DropDownHandler();
|
|||
|
itemUI.targetAttachment = null;
|
|||
|
itemUI.gameObject.transform.SetParent(go.transform);
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public void HandlePickup(PickUp storedPickUp)
|
|||
|
{
|
|||
|
if(storedPickUp != null && pickUpsInRange.Contains(storedPickUp))
|
|||
|
{
|
|||
|
Debug.Log("Picking up");
|
|||
|
storedPickUp.PickUpHandler();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void OnTriggerEnter(Collider other)
|
|||
|
{
|
|||
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|||
|
if (pickUpRange != null && !pickUpsInRange.Contains(pickUpRange.pickUp))
|
|||
|
{
|
|||
|
Debug.Log("Collided");
|
|||
|
pickUpsInRange.Add(pickUpRange.pickUp);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnTriggerStay(Collider other)
|
|||
|
{
|
|||
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|||
|
if (pickUpRange != null)
|
|||
|
{
|
|||
|
//CanPickupItem = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void OnTriggerExit(Collider other)
|
|||
|
{
|
|||
|
PickUpRange pickUpRange = other.GetComponent<PickUpRange>();
|
|||
|
if (pickUpRange != null && pickUpsInRange.Contains(pickUpRange.pickUp))
|
|||
|
{
|
|||
|
//CanPickupItem = false;
|
|||
|
|
|||
|
pickUpsInRange.Remove(pickUpRange.pickUp);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|