Ejemplo n.º 1
0
        private void SetFacingDirection(Vector2 direction, bool isMoving)
        {
            string animExtension = string.Empty;

            if (playerController != null)
            {
                animExtension = playerController.CurrentPlayerState.ToString();
            }
            if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
            {
                if (direction.x > JoystickMovementThreshold)
                {
                    CurrentDirection = Vector2.right;
                    spriteAnimator.PlayAnimation("WalkRight" + animExtension, !isMoving);
                }
                else if (direction.x < -JoystickMovementThreshold)
                {
                    CurrentDirection = Vector2.left;
                    spriteAnimator.PlayAnimation("WalkLeft" + animExtension, !isMoving);
                }
            }
            else
            {
                if (direction.y > JoystickMovementThreshold)
                {
                    CurrentDirection = Vector2.up;
                    spriteAnimator.PlayAnimation("WalkUp" + animExtension, !isMoving);
                }
                else if (direction.y < -JoystickMovementThreshold)
                {
                    CurrentDirection = Vector2.down;
                    spriteAnimator.PlayAnimation("WalkDown" + animExtension, !isMoving);
                }
            }
        }
Ejemplo n.º 2
0
        void Update()
        {
            if (DialogWindow.Instance.ActiveDialog)
            {
                // No player interaction during active dialog.
                return;
            }

            Vector3 currentPosition = transform.position;

            float   movementX  = Input.GetAxis("Horizontal");
            float   movementY  = Input.GetAxis("Vertical");
            var     movement   = new Vector2(movementX, movementY);
            Vector3 moveToward = currentPosition + new Vector3(movement.x, movement.y);

            if (movement.magnitude > JoystickMovementThreshold)
            {
                // 3
                // 4
                moveDirection   = moveToward - currentPosition;
                moveDirection.z = 0;
                moveDirection.Normalize();

                Vector3 target = moveDirection * 0.1f * moveSpeed + currentPosition;
                movementHandler.MoveToPosition(target, moveSpeed);
                //transform.position = Vector3.Lerp(currentPosition, target, Time.deltaTime);
            }
            else if (Input.GetButtonDown("Submit"))
            {
                if (CurrentPlayerState == PlayerState.Boy)
                {
                    CurrentPlayerState = PlayerState.Girl;
                    spriteAnimator.PlayAnimation("SwitchBoyGirl");
                }
                else
                {
                    CurrentPlayerState = PlayerState.Boy;
                    spriteAnimator.PlayAnimation("SwitchGirlBoy");
                }

                musicManager.SwitchGenderSounds(CurrentPlayerState);
            }
            else if (Input.GetButtonDown("Jump"))
            {
                Debug.Log("Jump" + movementHandler.CurrentDirection);
                var result = Physics2D.BoxCast(currentPosition, Vector2.one, 0f, movementHandler.CurrentDirection, 3f, LayerMask.GetMask("Interactables"));
                if (result)
                {
                    var isNpc = result.collider.gameObject.GetComponent <NpcBrain>();
                    if (isNpc != null)
                    {
                        isNpc.PlayerInitiatedDialog();
                    }

                    var isPickupItem = result.collider.gameObject.GetComponent <PickupItem>();
                    ReceiveItem(isPickupItem);
                }
            }
        }
    public void OnClicked_ZombeyIdle()
    {
        Debug.Log("Demo_SimpleSpriteAnimator : OnClicked_ZombeyIdle");

        if (m_ZombeyAnimator != null)
        {
            m_ZombeyAnimator.PlayAnimation("Idle");
        }
        else
        {
            Debug.LogError("Demo_SimpleSpriteAnimator : OnClicked_ZombeyIdle : m_ZombeyAnimator == null. Need setup with inspector to pulic value");
        }
    }