场景中的物品

master
SweetMe1ody 5 years ago
parent 70240e4b48
commit ca91d8a078

@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemInMap : MonoBehaviour
{
public Item thisItem;
public Inventory playerInventory;
Vector2 lookDirection = new Vector2(0, -1);
void Start()
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, lookDirection, 1.0f, LayerMask.GetMask("Cells"));
hit.collider.GetComponent<Cell>().SetOccupied(true);
}
public void AddNewItem()
{
if (!playerInventory.itemList.Contains(thisItem))
{
for (int i = 0; i < playerInventory.itemList.Count; i++)
{
if (playerInventory.itemList[i] == null)
{
playerInventory.itemList[i] = thisItem;
break;
}
}
}
else
{
thisItem.itemHeld += 1;
}
RaycastHit2D hit = Physics2D.Raycast(transform.position, lookDirection, 1.0f, LayerMask.GetMask("Cells"));
hit.collider.GetComponent<Cell>().SetOccupied(false);
InventoryManager.RefreshItem();
Destroy(gameObject);
}
}
Loading…
Cancel
Save