예제 #1
0
 public void UseItem(Item useItem)
 {
     useItem.UseItem();
     if (useItem.consumeOnUse)
     {
         CanvasControl.ConsumedItem(useItem);
         playerInventory.RemoveItem(useItem);
     }
 }
예제 #2
0
    void CameraUpdate()
    {
        while (blockMovement)
        {
            blockMovement = true;
        }
        //Naujas komentaras  2
        //Papildomas komentaras
        if (!blockMovement)
        {
            GameObject lookingAtObject = null;
            RaycastHit hit;
            Ray        ray = myCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            if (Physics.Raycast(ray, out hit, lookRange))
            {
                lookingAtObject = hit.collider.gameObject;
            }
            if (CurrentPickup != null)
            {
                if (KeepInput.KeyDown("Pick Item"))
                {
                    PickupPickup(CurrentPickup);
                    CurrentPickup = null;
                }
                if (KeepInput.KeyDown("Use Item"))
                {
                    CanvasControl.ConsumedItem(CurrentPickup.pickupItem);
                    if (CurrentPickup.pickupItem.UseItem())
                    {
                        Destroy(CurrentPickup.gameObject, Time.deltaTime);
                    }
                }
                if (KeepInput.KeyDown("Throw"))
                {
                    ThrowCarryItem();
                }
            }
            if (lookingAtObject != null)
            {
                Interactable findInteractable = lookingAtObject.GetComponent <Interactable>();
                if (findInteractable)
                {
                    string information = string.Empty;
                    if (findInteractable.canBeUsed)
                    {
                        information = KeepInput.ReturnKeyName("Interact") + " Interact";
                        if (KeepInput.KeyDown("Interact"))
                        {
                            findInteractable.Use();
                            return;
                        }
                    }
                    if (findInteractable is Pickup)
                    {
                        Pickup pickupReference = findInteractable as Pickup;
                        if (pickupReference.takeToInventory)
                        {
                            information += string.Format("\n{0} Take {1}", KeepInput.ReturnKeyName("Interact"), pickupReference.pickupItem.itemName);
                            if (KeepInput.KeyDown("Interact"))
                            {
                                PickupPickup(pickupReference);
                            }
                        }
                        information += string.Format("\n{0} Carry {1}", KeepInput.ReturnKeyName("Pick Item"), pickupReference.pickupItem.itemName);
                        if (KeepInput.KeyDown("Pick Item"))
                        {
                            CurrentPickup = pickupReference;
                        }
                    }
                    crosshairText.Text(information);
                }
                else
                {
                    crosshairText.Text(string.Empty);
                }
            }
            else
            {
                crosshairText.Text(string.Empty);
            }
        }
        else
        {
            crosshairText.Text(string.Empty);
        }
        if ((myBody.velocity.x != 0f || myBody.velocity.z != 0f) && IsGrounded)
        {
            myCamera.transform.localPosition = Vector3.Lerp(Vector3.up * 1.7f, Vector3.up * 1.9f, Mathf.Abs(Mathf.Sin(Time.time * 5f)));
        }
        else
        {
            myCamera.transform.localPosition = Vector3.Lerp(myCamera.transform.localPosition, Vector3.up * 1.8f, Time.deltaTime);
        }
        Quaternion handRotateTarget = carryHandRotation;

        if (!blockMovement)
        {
            handRotateTarget = Quaternion.Euler(carryHandRotation.eulerAngles + new Vector3(Input.GetAxis("Mouse Y") * 5f, 0f, Input.GetAxis("Mouse X") * 5f));
        }
        carryPoint.transform.localRotation = Quaternion.Slerp(carryPoint.transform.localRotation, handRotateTarget, Time.deltaTime * 5f);
    }