Beispiel #1
0
    public void Drop()
    {
        if (item == null || water.GetTile(water.WorldToCell(transform.position)) != null)
        {
            return;
        }

        if (item.name == "Stick")
        {
            //child.transform.localPosition = baton.localPosition;
            carryBois.SetActive(false);
        }

        GameObject itemDropped   = Instantiate(defaultPhysicItem, transform.position + 0.05f * Vector3.forward + 0.4f * Vector3.right * Mathf.Sign(transform.localScale.x), Quaternion.identity);
        PhysicItem itemDroppedPI = itemDropped.GetComponent <PhysicItem>();

        itemDroppedPI.item = item;
        itemDropped.name   = item.name;

        DropEvent?.Invoke(itemDropped.transform, item.name);

        item      = null;
        sR.sprite = null;
    }
Beispiel #2
0
    public void OnInteract(InputAction.CallbackContext ctx)
    {
        if (!ctx.performed || water.GetTile(water.WorldToCell(transform.position)) != null)
        {
            return;
        }

        if (playerMovement.animator.GetCurrentAnimatorStateInfo(0).IsName("player_kick"))
        {
            return;
        }

        // récup objet proche si il y en a un

        if (itemsNearby.Count > 0)
        {
            foreach (var i in itemsNearby)
            {
                Drop();
                PhysicItem physicItem = itemsNearby[0].GetComponent <PhysicItem>();
                if (!physicItem.canBePickedUp)
                {
                    continue;
                }
                item = physicItem.item;
                physicItem.PickedUp();
                sR.sprite = item.sprite;
                anim.Play("pick", -1, 0f);

                if (item.name == "Bone")
                {
                    PickupBone?.Invoke();
                }

                sM.PlaySound("Pickup");

                if (item.name == "Stick")
                {
                    //child.transform.localPosition = baton.localPosition;
                    carryBois.SetActive(true);
                    sR.sprite = null;
                }
                else
                {
                    child.transform.localPosition = normalItem.localPosition;
                }

                return;
            }
        }

        // cas ou pas d'obj proche
        foreach (InteractibleWithInteract interactible in interactiblesNearby)
        {
            if (interactible.needItem)
            {
                if (item == null || item.name != interactible.itemNeededName)
                {
                    continue;
                }
            }
            else
            {
                playerMovement.KickRequest();
            }
            // on est sorti si besoin d'item et pas le bon item

            if (interactible.needItem)
            {
                playerMovement.InteractionRequest(item.name);
            }
            interactible.OnInteraction();
            if (interactible.itemDestructionAfterUse)
            {
                item      = null;
                sR.sprite = null;
            }
            return;
        }

        // COUP DE PIED
        playerMovement.KickRequest();
    }