예제 #1
0
    public void DropItem()
    {
        if (heldItem != null)
        {
            Rigidbody itemRB = heldItem.GetComponentInChildren <Rigidbody>();

            if (itemRB != null)
            {
                itemRB.isKinematic = false;
            }

            ShockShot shot = heldItem.GetComponentInChildren <ShockShot>();
            if (shot != null)
            {
                shot.drawGizmos    = false;
                parentPlayer.m_gun = null;

                MeshRenderer meshRenderer = shot.GetComponentInChildren <MeshRenderer>();
                if (meshRenderer != null)
                {
                    meshRenderer.enabled = true;
                }

                if (visualWeaponObj != null)
                {
                    visualWeaponObj.SetActive(false);
                }
            }

            heldItem.transform.SetParent(null, true);
            heldItem = null;
        }
    }
예제 #2
0
    public void HoldItem(GameObject item)
    {
        if (heldItem != null) //Item already in hand
        {
            DropItem();
        }


        if (holdTransform != null)
        {
            heldItem = item;
            heldItem.transform.position      = holdTransform.position;
            heldItem.transform.forward       = transform.forward;
            item.transform.parent            = transform.parent;
            heldItem.transform.localRotation = holdTransform.localRotation;

            Rigidbody itemRB = heldItem.GetComponentInChildren <Rigidbody>();

            if (itemRB != null)
            {
                itemRB.isKinematic = true;
            }
        }

        ShockShot shot = heldItem.GetComponentInChildren <ShockShot>();

        if (shot != null)
        {
            shot.drawGizmos    = true;
            parentPlayer.m_gun = shot;
            FMODUnity.RuntimeManager.PlayOneShot("event:/SoundFX/Player/Pickup", transform.position);

            //Hide normal mesh
            MeshRenderer meshRenderer = shot.GetComponentInChildren <MeshRenderer>();
            if (meshRenderer != null)
            {
                meshRenderer.enabled = false;
                if (weaponTransform != null)
                {
                    heldItem.transform.position = weaponTransform.position;
                }

                if (visualWeaponObj != null)
                {
                    visualWeaponObj.SetActive(true);
                }
            }
        }
        else
        {
            FMODUnity.RuntimeManager.PlayOneShot("event:/SoundFX/Player/Landing", transform.position);
        }
    }