continuing fixes for dropping items

This commit is contained in:
tonyomendoza 2023-01-29 18:35:04 -08:00
parent 3e0ac77ed4
commit 05fcd17618
4 changed files with 14 additions and 3 deletions

View File

@ -41,15 +41,22 @@ namespace SimpleInventorySystem
{ {
GameObject gObj = Instantiate(prefabs[i]); GameObject gObj = Instantiate(prefabs[i]);
ItemUI item = gObj.GetComponentInChildren<ItemUI>(); ItemUI item = gObj.GetComponentInChildren<ItemUI>();
PickUp pickUp = gObj.GetComponentInChildren<PickUp>();
gObj.SetActive(true);
gObj.transform.position = Vector3.zero;
gObj.transform.SetParent(this.transform, false);
gObj.GetComponent<Rigidbody>().useGravity = false;
if(item != null) if(item != null)
{ {
item.gameObject.SetActive(true); item.gameObject.SetActive(true);
pickUp.gameObject.SetActive(true);
AddOwnership(item, this); AddOwnership(item, this);
//item.transform.SetParent(transform, true); //item.transform.SetParent(transform, true);
item.InitializeImageSize(); item.InitializeImageSize();
item.ResetTransform(); item.ResetTransform();
//gObj.transform.SetParent(item.transform, true); //gObj.transform.SetParent(item.transform, true);
gObj.SetActive(false); //gObj.SetActive(false);
//item.pickUp = gObj.GetComponentInChildren<PickUp>();
} }
} }
} }

View File

@ -54,6 +54,7 @@ namespace SimpleInventorySystem
else else
{ {
itemUI.pickUp = this; itemUI.pickUp = this;
Debug.Log("itemUI assigned:" + ItemGameObject.name);
} }
pickUpRange = GetComponentInChildren<PickUpRange>(); pickUpRange = GetComponentInChildren<PickUpRange>();

View File

@ -37,7 +37,10 @@ namespace SimpleInventorySystem
public void DetachItemGameObject(GameObject go, ItemUI itemUI) public void DetachItemGameObject(GameObject go, ItemUI itemUI)
{ {
itemUI.targetAttachment.DetachItemGameObject(go); if(itemUI.targetAttachment != null)
{
itemUI.targetAttachment.DetachItemGameObject(go);
}
itemUI.pickUp.DropDownHandler(); itemUI.pickUp.DropDownHandler();
itemUI.targetAttachment = null; itemUI.targetAttachment = null;
itemUI.gameObject.transform.SetParent(go.transform); itemUI.gameObject.transform.SetParent(go.transform);

View File

@ -1012,7 +1012,7 @@ Camera:
m_Depth: 0 m_Depth: 0
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 3355181055 m_Bits: 268173111
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 0} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0