can interact if player has tool selected (in hand))

This commit is contained in:
j.mei7
2022-02-18 20:25:35 +01:00
parent 73669eaa3f
commit 3ff90d47c2
30 changed files with 505 additions and 78 deletions

View File

@@ -7,4 +7,9 @@ public class FoodItem : Item
public int health;
public int water;
public int regeneration;
public override void OnSelect()
{
throw new System.NotImplementedException();
}
}

View File

@@ -25,6 +25,7 @@ public class Inventory : MonoBehaviour
public delegate void OnItemChanged();
public OnItemChanged onItemChangedCallback; //
[SerializeField]
List<Slot> inventory = new List<Slot>();
public List<Slot> getInventory { get => inventory;}
@@ -33,7 +34,6 @@ public class Inventory : MonoBehaviour
// Initializes the inventory with a specific number of slots and slotsize.
// !!!Has to be called bevore adding any items!!!
// Example createEmptyInventory(5, 10) : 5 Slots with space for 10 items each
inventory = new List<Slot>();
for (int i = 0; i < numberOfSlots; i++)
{
inventory.Add(new Slot(maxSpaceOfSlots));

View File

@@ -6,15 +6,20 @@ public class InventoryController : MonoBehaviour
{
[SerializeField] Item item1;// not needed
[SerializeField] Item item2;// not needed
public Item selectedItem;
Item testItem;
public Inventory inventory;
[SerializeField] UI_Inventory uiInventory;
private void Awake()
{
inventory = transform.GetComponent<Inventory>();
inventory.createEmptyInventory(8,10);
testItem = Instantiate(item1);
inventory.addItemAt(0, item1, 8);
inventory.addItemAt(0, item1, 1);
inventory.addItemAt(0, testItem, 1);
inventory.addItemAt(3, item2, 15);
inventory.addItemAt(4, item1, 3);
@@ -24,7 +29,9 @@ public class InventoryController : MonoBehaviour
Debug.Log(inventory.removeItemAt(0, 10));
Debug.Log(inventory.getInventory[0].Count);
*/
uiInventory.setInventory(inventory);
// uiInventory.setInventory(inventory);
}
void Start()
{
@@ -34,6 +41,14 @@ public class InventoryController : MonoBehaviour
// Update is called once per frame
void Update()
{
// FOR DEBUG
if (Input.GetKeyDown(KeyCode.X))
{
testItem.Select();
if(testItem.isSelected)
selectedItem = testItem;
else
selectedItem = null;
}
}
}

View File

@@ -3,10 +3,19 @@ using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Item", menuName = "Items/Item", order = 1)]
public class Item : ScriptableObject
public abstract class Item : ScriptableObject
{
public new string name;
public int id;
public bool isStackable;
public Sprite sprite;
public bool isSelected;
public abstract void OnSelect();
public void Select()
{
isSelected = !isSelected;
OnSelect();
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 07c440f0b142b6c43818e32e4a43686c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c9a450f431b33414ab3a1f3b08250700, type: 3}
m_Name: Stick
m_EditorClassIdentifier:
name: stick
id: 10
isStackable: 0
sprite: {fileID: 21300000, guid: 8994265d0b3152b4cb238bdf03e8d440, type: 3}
isSelected: 0
toolType: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cada8a20c35f0bd4a93d92e1152e5625
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "FoodItem", menuName = "Items/FoodItem", order = 2)]
public class ResourceItem : Item
{
public override void OnSelect()
{
throw new System.NotImplementedException();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0fae7bba50a98204883e78d8d6c96fc2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
[CreateAssetMenu(fileName = "ToolItem", menuName = "Items/Tool", order = 2)]
public class ToolItem : Item
{
public ToolType toolType;
float durability = 1f;
SpriteRenderer playerHandSpriteRenderer;
public override void OnSelect()
{
playerHandSpriteRenderer = GameObject.Find("Player").transform.Find("Hand").gameObject.GetComponent<SpriteRenderer>();
if (isSelected)
{
playerHandSpriteRenderer.GetComponent<SpriteRenderer>().sprite = sprite;
}
else
{
playerHandSpriteRenderer.GetComponent<SpriteRenderer>().sprite = null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9a450f431b33414ab3a1f3b08250700
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum ToolType
{
AXE,
PICKAXE,
HOE,
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f9fcb5700fbcfa4d93940e88f197200
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: