예제 #1
0
        /// <summary>
        /// Update should be used to perform user input actions such as triggering an attack
        /// You can edit this function to replace the Keyboard buttons with your own input scheme.
        /// For example, you could use on screen buttons to detect input.
        /// </summary>
        void Update()
        {
            // Start out with no actions to perform
            Character.Action actionFlags = 0;

            // Check if we are modifying the run speed
            actionFlags |= (Input.GetAxisRaw("Vertical") < 0 ? Character.Action.RunModified : 0);

            // Check if we are crouching (which is the same as run speed modifer in our demo)
            actionFlags |= (Input.GetAxisRaw("Vertical") < 0 ? Character.Action.Crouch : 0);

            // Check if we are jumping
            actionFlags |= (Input.GetButtonDown("Jump") ? Character.Action.Jump : 0);

            // Check if we are jumping down off a platform
            actionFlags |= (Input.GetButtonDown("Jump") && Input.GetAxisRaw("Vertical") < 0 ? Character.Action.JumpDown : 0);

            // Check if they are holding down block
            actionFlags |= (Input.GetKey(KeyCode.B) ? Character.Action.Block : 0);

            // Check the other actions
            actionFlags |= (Input.GetButtonDown("Fire1") ? Character.Action.QuickAttack : 0);
            actionFlags |= (Input.GetButtonDown("Fire2") ? Character.Action.Attack : 0);
            actionFlags |= (Input.GetButtonDown("Fire3") ? Character.Action.Cast : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.Z) ? Character.Action.ThrowOff : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.X) ? Character.Action.ThromMain : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.C) ? Character.Action.Consume : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.H) ? Character.Action.Hurt : 0);

            // Now trigger the current actions on the character
            this.character.Perform(actionFlags);
        }
예제 #2
0
        /// <summary>
        /// Update should be used to perform user input actions such as triggering an attack
        /// You can edit this function to replace the Keyboard buttons with your own input scheme.
        /// For example, you could use on screen buttons to detect input.
        /// </summary>
        void Update()
        {
            // Start out with no actions to perform
            Character.Action actionFlags = 0;

            // Check if we are modifying the run speed
            actionFlags |= (Input.GetAxisRaw("Vertical") < 0 ? Character.Action.RunModified : 0);

            // Check if we are crouching (which is the same as run speed modifer in our demo)
            actionFlags |= (Input.GetAxisRaw("Vertical") < 0 ? Character.Action.Crouch : 0);

            // Check if we are jumping
            actionFlags |= (Input.GetButtonDown("Jump") ? Character.Action.Jump : 0);

            // Check if we are jumping down off a platform
            actionFlags |= (Input.GetButtonDown("Jump") && Input.GetAxisRaw("Vertical") < 0 ? Character.Action.JumpDown : 0);

            // Check if they are holding down block
            actionFlags |= (Input.GetKey(KeyCode.B) ? Character.Action.Block : 0);

            // Check the other actions
            actionFlags |= (Input.GetButtonDown("Fire1") ? Character.Action.QuickAttack : 0);
            actionFlags |= (Input.GetButtonDown("Fire2") ? Character.Action.Attack : 0);
            actionFlags |= (Input.GetButtonDown("Fire3") ? Character.Action.Cast : 0);
            actionFlags |= (Input.GetButtonUp("Fire3") ? Character.Action.StopCasting : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.Z) ? Character.Action.ThrowOff : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.X) ? Character.Action.ThromMain : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.C) ? Character.Action.Consume : 0);
            actionFlags |= (Input.GetKeyDown(KeyCode.H) ? Character.Action.Hurt : 0);

            // Now trigger the current actions on the character
            this.character.Perform(actionFlags);

            // toolbar
            if (!isKeyPressed())
            {
                return;
            }
            pressedKey = Input.inputString[0] - 48;
            if (pressedKey > 0 && pressedKey <= 9)
            {
                if (character.isCasting)
                {
                    character.CancelCasting();
                }
                spellbook.SetToolbar(pressedKey);
            }
        }
예제 #3
0
        private void Animate(Character c)
        {
            // Pick the correct animation action and play it
            Character.Action actionFlags = Character.Action.ThromMain;
            switch (c.EquippedWeaponType)
            {
            case Character.WeaponType.None:
            case Character.WeaponType.Bow:
            case Character.WeaponType.Gun:
                actionFlags = Character.Action.Attack;
                break;
            }
            c.Perform(actionFlags);

            // Wait for the animation to finish and see if the game is over,
            // Ideally we would have a callback on the character for when they died instead of polling like this.
            StartCoroutine(this.CheckGameState(3));
        }
예제 #4
0
        void Update()
        {
            // Move the sea level a bit to make a nice effect
            this.waveTime += Time.deltaTime;
            for (int i = 0; i < this.Waves.Length; i++)
            {
                float y = Mathf.Sin(this.waveTime * Mathf.PI) * 0.003f;
                this.Waves[i].localPosition += Vector3.up * y;
            }

            if (this.player == null)
            {
                return;
            }

            // Get the player input for movement
            this.axis.x = Input.GetAxis("Horizontal");
            this.axis.y = Input.GetAxis("Vertical");
            this.axis.Normalize();

            // Set the animations and direction
            float movement = Mathf.Abs(this.axis.x) + Mathf.Abs(this.axis.y);

            this.animator.SetFloat("VelocityX", movement);
            this.animator.SetBool("HasMoveInput", movement > 0);
            if (this.axis.x != 0)
            {
                this.player.ForceDirection(this.axis.x < 0 ? Character.Direction.Left : Character.Direction.Right);
            }

            // Check for a chopping action
            Character.Action actionFlags = 0;
            actionFlags |= (Input.GetButtonDown("Fire1") ? Character.Action.QuickAttack : 0);
            this.player.Perform(actionFlags);

            if (actionFlags != 0)
            {
                StartCoroutine(this.ChopTree());
            }
        }