Пример #1
0
    void Update()
    {
        if (isServer)
        {
            if (GetComponent <Damageable> ().IsDead() && state != ActionState.DEAD)
            {
                RpcKillPlayer();
            }

            for (int i = 0; i < messageList.Count; i++)
            {
                PlayerMessage m = messageList [i];
                if (m.timed)
                {
                    m.elapsed += Time.deltaTime;
                    m.percent  = 1 - (m.elapsed / m.fullTime);
                }
                messageList [i] = m;
            }
            int index = 0;
            while (index < messageList.Count)
            {
                if (messageList [index].timed && messageList [index].elapsed >= messageList [index].fullTime)
                {
                    messageList.RemoveAt(index);
                }
                else
                {
                    index++;
                }
            }
        }

        if (state == ActionState.PAUSED)
        {
            canUse    = false;
            canDrop   = false;
            canMelee  = false;
            canSwitch = false;
            playerActor.canInteract = false;
            playerMove.canJump      = false;
            playerMove.canMove      = false;
            playerMove.canMoveHead  = false;
            playerMove.canTurnBody  = false;
        }
        else if (state == ActionState.FREE)
        {
            canUse    = true;
            canDrop   = true;
            canMelee  = true;
            canSwitch = true;
            playerActor.canInteract = true;
            playerMove.canJump      = true;
            playerMove.canMove      = true;
            playerMove.canMoveHead  = true;
            playerMove.canTurnBody  = true;
        }
        else if (state == ActionState.ACTING)
        {
            canUse    = action.canUseItems;
            canDrop   = action.canDrop;
            canMelee  = false;
            canSwitch = action.canSwitchItems;
            playerActor.canInteract = action.canInteract;
            playerMove.canJump      = action.canJump;
            playerMove.canMove      = action.canMove;
            playerMove.canMoveHead  = action.canCameraTurn;
            playerMove.canTurnBody  = action.canTurnBody;
        }
        else if (state == ActionState.DEAD)
        {
            canUse    = false;
            canDrop   = false;
            canMelee  = false;
            canSwitch = false;
            playerActor.canInteract = false;
            playerMove.canJump      = false;
            playerMove.canMove      = false;
            playerMove.canMoveHead  = false;
            playerMove.canTurnBody  = false;
        }
        else if (state == ActionState.COOLDOWN)
        {
            cooldownRemain -= Time.deltaTime;
            if (cooldownRemain <= 0)
            {
                state     = ActionState.FREE;
                canUse    = true;
                canDrop   = true;
                canMelee  = true;
                canSwitch = true;
                playerActor.canInteract = true;
                playerMove.canJump      = true;
                playerMove.canMove      = true;
                playerMove.canMoveHead  = true;
                playerMove.canTurnBody  = true;
            }
            else
            {
                canUse    = false;
                canDrop   = true;
                canMelee  = false;
                canSwitch = true;
                playerActor.canInteract = false;
                playerMove.canJump      = true;
                playerMove.canMove      = true;
                playerMove.canMoveHead  = true;
                playerMove.canTurnBody  = true;
            }
        }
        prevState = state;

        if (isLocalPlayer)
        {
            if (Input.GetButton("Interact"))
            {
                playerActor.InteractWithObject();
            }
            if (canDrop && Input.GetButton("Drop") && inventory.IsHoldingItem())
            {
                if (inventory.held.GetComponent <Item> ().canDrop)
                {
                    inventory.DropItem(inventory.items[inventory.selected], inventory.selected);
                }
                else
                {
                    CmdEndAction(1.0f, "Can't drop that");
                }
            }
            if (canUse && Input.GetButton("Use") && inventory.IsHoldingItem() && !prevHeld)
            {
                CmdUse();
            }
            if (canMelee && Input.GetButton("Special1"))
            {
                CmdSpecial1();
            }
            if (canMelee && Input.GetButton("Melee"))
            {
                attacker.CmdAttemptMeleeAttack();
            }
            if (canSwitch)
            {
                if (Input.GetAxis("Mouse ScrollWheel") < 0)
                {
                    inventory.selected += 1;
                    if (inventory.selected >= inventory.items.Length)
                    {
                        inventory.selected = 0;
                    }
                }
                else if (Input.GetAxis("Mouse ScrollWheel") > 0)
                {
                    inventory.selected -= 1;
                    if (inventory.selected < 0)
                    {
                        inventory.selected = inventory.items.Length - 1;
                    }
                }
            }
            prevHeld = Input.GetButton("Use");
        }
    }