UWCharacter.GetUseRange C# (CSharp) Method

GetUseRange() public method

public GetUseRange ( ) : float
return float
    public override float GetUseRange()
    {
        if (isTelekinetic==true)
        {
            return useRange*8.0f;
        }
        else
        {

            if (playerInventory.GetObjectInHand() =="")
            {
                return useRange;
            }
            else
            {//Test if this is a pole. If so extend the use range by a small amount.
                ObjectInteraction objIntInHand = playerInventory.GetGameObjectInHand().GetComponent<ObjectInteraction>();
                if (objIntInHand!=null)
                {
                    switch (objIntInHand.GetItemType())
                    {
                        case ObjectInteraction.POLE:
                            return useRange *2;
                    }
                }
                return useRange;
            }
        }
    }

Usage Example

    protected override void UseObjectInHand()
    {
        base.UseObjectInHand();
        if (playerUW.playerInventory.ObjectInHand != "")
        {        //The player is holding something
            //Determine what is directly in front of the player via a raycast
            //If something is in the way then cancel the drop
            Ray ray;
            if (playerUW.MouseLookEnabled == true)
            {
                ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }

            RaycastHit hit = new RaycastHit();

            if (Physics.Raycast(ray, out hit, playerUW.GetUseRange()))
            {
                if (hit.transform.gameObject.GetComponent <ObjectInteraction>() != null)
                {
                    hit.transform.gameObject.GetComponent <ObjectInteraction>().Use();
                }
                else
                {
                    playerUW.CursorIcon = playerUW.CursorIconDefault;
                    playerUW.playerInventory.ObjectInHand = "";
                }
            }
            else
            {
                playerUW.CursorIcon = playerUW.CursorIconDefault;
                playerUW.playerInventory.ObjectInHand = "";
            }
        }
    }