示例#1
0
        // Called by the InteractionSystem when an interaction is paused (on trigger)
        private void OnPause(FullBodyBipedEffector effectorType, InteractionObject interactionObject)
        {
            if (effectorType != FullBodyBipedEffector.LeftHand)
            {
                return;
            }
            if (interactionObject != obj)
            {
                return;
            }

            // Make the object inherit the character's movement
            obj.transform.parent = interactionSystem.transform;

            // Make the object kinematic
            var r = obj.GetComponent <Rigidbody>();

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

            // Set object pick up position and rotation to current
            pickUpPosition = obj.transform.position;
            pickUpRotation = obj.transform.rotation;
            holdWeight     = 0f;
            holdWeightVel  = 0f;
        }
示例#2
0
        public override bool CanUse(Player player, InteractionObject target)
        {
            if (target.objectType != ObjectType.Stump)
            {
                return(false);
            }
            TreeStump treeStump = target.GetComponent <TreeStump>();

            return(treeStump != null && player.Stamina >= treeStump.staminaCost);
        }
示例#3
0
        // Called by the InteractionSystem when an interaction is paused (on trigger)
        private void OnPause(FullBodyBipedEffector effectorType, InteractionObject interactionObject)
        {
            if (effectorType != FullBodyBipedEffector.LeftHand)
            {
                return;
            }

            // Make the box inherit the character's movement
            box.transform.parent = interactionSystem.transform;

            // Make the box kinematic
            if (box.GetComponent <Rigidbody>() != null)
            {
                box.GetComponent <Rigidbody>().isKinematic = true;
            }

            // Set box lerping speed to 0 so we can smoothly accelerate picking up from that
            currentBoxLerpSpeed = 0f;
        }
    public void AttemptExitEnd(InteractionObject obj)
    {
        if (numberOfPapers == 0)
        {
            var closeSound = obj.GetComponent<AudioSource>();
            if (closeSound != null)
                closeSound.Play();

            StartCoroutine(ExitCoroutine());
        }
    }
示例#5
0
        public override void UseTool(Player player, InteractionObject target, GameObject toolObject)
        {
            if (CanUse(player, target))
            {
                toolObject.GetComponent <Animator>().SetTrigger("Use");
                Rock rock = target.GetComponent <Rock>();
                player.Stamina -= rock.staminaCost;

                rock.health--;
                if (rock.health <= 0)
                {
                    ScoreManager.Instance.stones += rock.stoneYield;
                    Destroy(rock.gameObject);
                }
            }
        }
示例#6
0
        public override void UseTool(Player player, InteractionObject target, GameObject toolObject)
        {
            if (!CanUse(player, target))
            {
                return;
            }
            toolObject.GetComponent <Animator>().SetTrigger("Use");
            TreeStump treeStump = target.GetComponent <TreeStump>();

            player.Stamina -= treeStump.staminaCost;
            treeStump.health--;
            if (treeStump.health <= 0)
            {
                ScoreManager.Instance.wood += treeStump.woodYield;
                Destroy(target.gameObject);
            }
        }
    private void FixedUpdate()
    {
        weaponPickedUp = false;
        ammoCollected  = false;
        isColliding    = false;
        if (Input.GetButtonDown("Interact") && currentInterObj)
        {
            //check to see if this object is to be stored in inventory

            if (currentInterObjScript.inventory)
            {
                inventory.AddItem(currentInterObj);
            }
            if (currentInterObjScript.equippable && currentInterObj != null)
            {
                oldWeapon = player.activeSlot.transform.GetChild(0).GetComponent <WeaponReference>().pickupReference;
                Instantiate(oldWeapon, player.transform.position + Random.insideUnitSphere, Quaternion.identity); //Instantiate gammelt våpen på bakken

                inventory.AddItem(weapon);
                Destroy(player.activeSlot.transform.GetChild(0).gameObject);
                weaponPickedUp  = true;
                currentInterObj = null;
            }
            if (currentInterObjScript.hasAttributes)
            {
                playerAttributes.StatChange(currentInterObj.GetComponent <Attributes>());
                Destroy(currentInterObjScript.gameObject);
            }
            if (currentInterObjScript.hasAbilities)
            {
                print(currentInterObjScript.GetComponent <Abilities>().name);
                playerAbilities.AbilityChange(currentInterObj.GetComponent <Abilities>());
                Destroy(currentInterObjScript.gameObject);
            }
            if (currentInterObjScript.shop)
            {
                GameObject item       = currentInterObjScript.itemContained;
                ItemInfo   itemInfo   = currentInterObjScript.itemContained.GetComponent <ItemInfo>();
                var        totalPrice = currentInterObjScript.price + itemInfo.price;
                print(totalPrice);
                if (inventory.money - totalPrice >= 0)
                {
                    inventory.money = inventory.money - totalPrice;
                    if (item.tag == "Weapon")
                    {
                        if (player.activeSlot.transform.GetChild(0).tag == "Unarmed")
                        {
                            weapon = item.GetComponent <WeaponReference>().gunReference;
                            inventory.AddItem(weapon);
                            Destroy(player.activeSlot.transform.GetChild(0).gameObject);

                            player.weapon = player.activeSlot.transform.GetChild(0).GetComponent <BaseWeapon>();
                            Destroy(currentInterObj.gameObject);
                        }

                        if (player.activeSlot.transform.GetChild(0).tag == "Weapon")
                        {
                            weapon        = item.gameObject.GetComponent <WeaponReference>().gunReference;
                            player.weapon = player.activeSlot.transform.GetChild(0).GetComponent <BaseWeapon>();
                            oldWeapon     = player.activeSlot.transform.GetChild(0).GetComponent <WeaponReference>().pickupReference;
                            Instantiate(oldWeapon, player.transform.position + Random.insideUnitSphere, Quaternion.identity); //Instantiate gammelt våpen på bakken

                            inventory.AddItem(weapon);
                            Destroy(player.activeSlot.transform.GetChild(0).gameObject);
                            currentInterObj.gameObject.SetActive(false);

                            weaponPickedUp  = true;
                            currentInterObj = null;
                        }
                    }
                    //Destroy(currentInterObjScript.gameObject);
                }
            }



            //check to see if this object can be opened
            if (currentInterObjScript.openable)
            {
                //check to see if the object is locked
                if (currentInterObjScript.locked)
                {
                    //check to see if we have the object needed to unlock
                    //search our inventory for item needed, if found , unlock object
                    if (inventory.FindItem(currentInterObjScript.ItemNeeded))
                    {
                        //we found the item needed
                        currentInterObjScript.locked = false;
                        Debug.Log(currentInterObj.name + " was unlocked");
                    }
                    else
                    {
                        Debug.Log(currentInterObj.name + (" is locked"));
                    }
                }
                else
                {
                    //object is not locked - open the object

                    door = currentInterObj.GetComponent <Door>();
                    door.Open();
                }
            }
            if (currentInterObjScript.hasInventory)
            {
                chest = currentInterObj.GetComponent <Chest>();
                chest.Open();
            }
        }
    }
示例#8
0
        public override bool CanUse(Player player, InteractionObject target)
        {
            Rock rock = target.GetComponent <Rock>();

            return(target.objectType == ObjectType.Rock && player.Stamina >= rock.staminaCost);
        }
示例#9
0
    void HandleInteraction(InteractionObject io)
    {
        if (io != currentInteractionObject || (io != null && io.IsDirty))
        {
            if (io == null)
            {
                currentInteractionObject.interactionSystem = null;
            }
            else
            {
                io.interactionSystem = this;
            }

            PopulateOptions(io);
            scrollIndex = 0;

            if (io != null && io.IsDirty)
            {
                io.ClearDirty();
            }
        }

        currentInteractionObject = io;

        if (io == null && lastHighlight != null)
        {
            lastHighlight.StopHighlighting();
            lastHighlight = null;
        }



        if (io == null)
        {
            return;
        }


        List <InteractionOption> ActiveOptions = io.Options.Where(a => a.Validate == null || a.Validate.Invoke()).ToList();

        if (io != null && ActiveOptions.Count > 0)
        {
            scrollIndex  = Mathf.Clamp(scrollIndex, 0f, ActiveOptions.Count - 1);
            scrollIndex += -Input.mouseScrollDelta.y;
            optionIndex  = Mathf.RoundToInt(scrollIndex);
        }



        if (UI_Options.Count >= optionIndex)
        {
            UI_Options[optionIndex].GetComponent <Selectable>().Select();
        }

        if (io.GetComponent <InteractionHighlight>())
        {
            var highlight = io.GetComponent <InteractionHighlight>();

            if (lastHighlight != null && lastHighlight != highlight)
            {
                lastHighlight.StopHighlighting();
            }

            lastHighlight = highlight;
            lastHighlight.Highlight();
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            io.OnInteraction(this, optionIndex);
        }
    }