using System.Collections; using System.Collections.Generic; using UnityEngine; namespace SimpleInventorySystem { public class TargetAttachment : MonoBehaviour { public ItemTags itemTag; private GameObject itemGameObject; public Vector3 position; public Vector3 rotation; public Vector3 scale = Vector3.one; public bool hideGameObject; public bool KeepOldRotationOnDrop; private Vector3 oldRotation = new Vector3(); public bool AttachItemGameObject(GameObject go, ItemTags targetItemTag, PickUp pickUp) { if (itemTag == targetItemTag || itemTag == ItemTags.Any) { itemGameObject = go; if (hideGameObject) { itemGameObject.SetActive(false); return true; } oldRotation = go.transform.localRotation.eulerAngles; go.transform.SetParent(transform, false); if(pickUp == null) { go.transform.localPosition = position; go.transform.localRotation = Quaternion.Euler(rotation); go.transform.localScale = scale; } else { pickUp.AlterItemGameObjectTransform(); } // TODO: possibly handle transform rotations, scales, etc. return true; } return false; } public void DetachItemGameObject(GameObject go) { if (hideGameObject) { itemGameObject.SetActive(true); } itemGameObject = null; // TODO: Most likely, implement drop here. go.transform.SetParent(null); go.transform.localRotation = Quaternion.Euler(oldRotation); } } }