예제 #1
0
    private void Update()
    {
        if (usable != null)
        {
            if (usable.active == false)
            {
                usable = null;
            }
        }

        //hold usable
        if (usable != null && usable.hold == false && Input.GetKeyDown(KeyCode.E))
        {
            usable.Use();
        }
        //not hold usable
        if (usable != null && usable.hold == true && Input.GetKey(KeyCode.E))
        {
            usable.Use();
        }

        if (usable == null)
        {
            useText.SetActive(false);
        }
    }
예제 #2
0
 public void UseItem()
 {
     if (storedItem != null)
     {
         storedItem.Use(fireTurret);
     }
 }
예제 #3
0
 void Interact()
 {
     if (objectToUse != null)
     {
         isUsingObject = true;
         objectToUse.Use(this);
     }
 }
예제 #4
0
    private void AttemptToUse(Collider other)
    {
        Usable usable = other.gameObject.GetComponent <Usable>();

        if (usable)
        {
            usable.Use();
        }
    }
예제 #5
0
 // Update is called once per frame
 void Update()
 {
     //use button is E
     if (Input.GetButtonDown("Use"))
     {
         if (PickUp.IsHoldingObject())
         {
             Usable usable = PickUp.HeldObject().GetComponent <Usable>();
             if (usable != null)
             {
                 usable.Use();
                 Debug.Log("use Pressed");
             }
         }
     }
 }
예제 #6
0
    void UpdateUse(float dT)
    {
        bool checkUse = controls.IsUse();

        if (checkUse)
        {
            if (liftTarget)
            {
                Tool tool = liftTarget.GetComponent <Tool>() as Tool;
                if (tool)
                {
                    tool.user = this;
                    tool.Use();
                    return;
                }
            }

            if (useTarget != null)
            {
                if (
                    DistanceSquaredTo(useTarget.transform.position) < useDistanceSquared &&
                    IsFacing(useTarget.transform.position, useAngle)
                    )
                {
                    useTarget.Use(dT);
                    UpdateLookAtPosition(useTarget.transform.position, dT, turnSpeed);
                }
                else
                {
                    useTarget = null;
                }
            }

            if (useTarget == null)
            {
                Usable curTarget = GetClosestUsable(useDistanceSquared);
                if (curTarget)
                {
                    useTarget = curTarget;
                }
            }
        }
        else
        {
            useTarget = null;
        }
    }
    private void UseItem()
    {
        Item item = data.inventory.content[data.currentItem].item;

        if (item is Weapon)
        {
            data.player.EquipWeapon((Weapon)item);
        }
        if (item is Armor)
        {
            data.player.EquipArmor((Armor)item);
        }
        if (item is Throwable)
        {
            Throwable t = (Throwable)item;

            data.inventory.content[data.currentItem].count -= 1;
            // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items
            bool temp = t.Use();

            if (data.inventory.content[data.currentItem].count == 0 && temp)
            {
                data.inventory.content.RemoveAt(data.currentItem);
                data.currentItem = -1;
            }

            data.player.actions--;
            QuitInventory();
        }
        if (item is Usable)
        {
            Usable u = (Usable)item;

            data.inventory.content[data.currentItem].count -= 1;
            // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items
            if (data.inventory.content[data.currentItem].count == 0)
            {
                data.inventory.content.RemoveAt(data.currentItem);
                data.currentItem = -1;
            }

            u.Use();
            data.player.actions--;
            QuitInventory();
        }
    }
예제 #8
0
    public void UseButtonClicked()
    {
        Usable u = (Usable)currentItem;

        u.Use();
        cooldown[u.GetType()]     = u.cooldown + 1;
        availability[u.GetType()] = false;
        if (typeof(Consumable).IsInstanceOfType(currentItem))
        {
            Consumable c = (Consumable)currentItem;
            if (c.amount == 0)
            {
                Remove(c);
                ClearSelection();
            }
            amountText.GetComponent <TextMeshProUGUI>().text = c.amount.ToString();
        }
    }
예제 #9
0
 void UseItem()
 {
     if (PlayerManager.Instance.playerDisabled)
     {
         return;
     }
     itemUsing = PlayerManager.Instance.PlayerUsableList[PlayerManager.Instance.usableSelected];
     if (itemUsing == null)
     {
         return;
     }
     if (itemUsing.ammount <= 0)
     {
         Debug.Log("Cantidad: " + itemUsing.ammount); return;
     }
     itemUsing.Use();
     Debug.Log("Ha sido usado el item: " + itemUsing.itemName + ". En la posición: " + PlayerManager.Instance.usableSelected + " del array");
 }
예제 #10
0
파일: Become.cs 프로젝트: Justinel2/ISLAND
    //player actions
    private void PlayerActions()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        RigidBodyController controller = GetComponentInParent <RigidBodyController>();

        controller.Locomote(new Vector3(horizontal, 0, vertical));
        controller.Rotate();


        if (Input.GetKeyDown(KeyCode.Space))
        {
            controller.Jump();
        }

        if (Input.GetMouseButtonDown(0))
        {
            //become other player on left click
            CreateRay();
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            if (CamMode == 1)
            {
                CamMode = 0;
            }
            else
            {
                CamMode++;
            }
            StartCoroutine(CamChange());
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            if (actionPickup && actionPickup.IsHoldingObject())
            {
                Usable usable = actionPickup.HeldObject().GetComponent <Usable>();
                if (usable)
                {
                    usable.Use();
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            //call spawn function
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            //call pickup function
            actionPickup = GetComponentInParent <Pickupper2>();
            actionPickup.PickUp();
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            //call eat function
            actionEat = GetComponentInParent <Eat>();
            actionEat.EatFood();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            if (actionPickup && actionThrow && actionPickup.IsHoldingObject())
            {
                actionThrow.ThrowObject();
            }
        }
        //... more actions
    }
예제 #11
0
    //player actions
    private void PlayerActions()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        RigidBodyController controller = GetComponentInParent <RigidBodyController>();

        controller.Locomote(new Vector3(horizontal, 0, vertical));
        controller.Rotate();


        if (Input.GetKeyDown(KeyCode.Space))
        {
            controller.Jump();
        }

        if (Input.GetMouseButtonDown(0))
        {
            //become other player on left click
            CreateRay();
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            if (CamMode == 1)
            {
                CamMode = 0;
            }
            else
            {
                CamMode++;
            }
            StartCoroutine(CamChange());
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            if (actionPickup && actionPickup.IsHoldingObject())
            {
                Usable usable = actionPickup.HeldObject().GetComponent <Usable>();
                if (usable)
                {
                    usable.Use();
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            //checks for the actionpickup script and if it is holding an object
            if (actionPickup && actionPickup.IsHoldingObject())
            {
                //check if the picked up item has a spawner script
                //get the spawner script in the children component of pickupper script
                actionSpawn = actionPickup.GetComponentInChildren <Spawner>();
                //call spawn function
                actionSpawn.Spawn();
            }
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            //call pickup function
            actionPickup = GetComponentInParent <Pickupper>();
            actionPickup.PickUp();
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            dropItem = GetComponentInParent <DropItem>();
            dropItem.DropHeldObject();
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            //call eat function
            actionEat = GetComponentInParent <Eat>();
            actionEat.EatFood();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            /*
             *  actionThrow = GetComponentInParent<Throw>();
             *  actionThrow.ThrowObject();
             */
        }
        //... more actions
    }
예제 #12
0
 void InstantActivateItem(Usable ItemUsable)
 {
     ItemUsable.launcher = _player;
     ItemUsable.Use(fireTurret);
 }