private void DropHeldWeapon() { Vector3 launchForce = transform.forward * itemDropForce; GameObject droppedWeapon = rightHand.GetComponentInChildren <BaseWeapon>().gameObject; if (!droppedWeapon) { return; } GameObject newWorldItem = WorldItem.CreateWorldItem(transform.position, transform.rotation, droppedWeapon, launchForce); interactor.DroppedObject(newWorldItem); }
// Create a new world item based and add our child item to it public static GameObject CreateWorldItem(Vector3 position, Quaternion rotation, GameObject itemObject, Vector3 force) { if (staticWorldItemPrefab == null) { staticWorldItemPrefab = Resources.Load <GameObject>("Prefabs/WorldItem"); } WorldItem newWorldItem = Instantiate(staticWorldItemPrefab, position, rotation).GetComponent <WorldItem>(); itemObject.transform.parent = newWorldItem.transform; itemObject.transform.localPosition = Vector3.zero; itemObject.transform.localRotation = Quaternion.identity; newWorldItem.childObject = itemObject; newWorldItem.GetComponent <Rigidbody>().AddForce(force); return(newWorldItem.gameObject); }