Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        h = manager.isAction ? 0 : Input.GetAxisRaw("Horizontal");
        v = manager.isAction ? 0 : Input.GetAxisRaw("Vertical");

        bool hDown = manager.isAction ? false : Input.GetButtonDown("Horizontal");
        bool vDown = manager.isAction ? false : Input.GetButtonDown("Vertical");
        bool hUp   = manager.isAction ? false : Input.GetButtonUp("Horizontal");
        bool vUp   = manager.isAction ? false : Input.GetButtonUp("Vertical");

        //check horizontal move
        if (hDown)
        {
            isHorizonMove = true;
        }
        else if (vDown)
        {
            isHorizonMove = false;
        }
        else if (hUp || vUp)
        {
            isHorizonMove = h != 0;
        }

        if (!hDown && !vDown && !hUp && !vUp)
        {
            anim.SetBool("isChange", false);
        }

        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow))
        {
            anim.SetBool("isChange", true);
        }



        //animation
        if (anim.GetInteger("hAxisRaw") != h)
        {
            //anim.SetBool("isChange", true);
            anim.SetInteger("hAxisRaw", (int)h);
        }
        else if (anim.GetInteger("vAxisRaw") != v)
        {
            //anim.SetBool("isChange", true);
            anim.SetInteger("vAxisRaw", (int)v);
        }

        //direction
        if (vDown && v == 1)
        {
            dirVec = Vector3.up;
        }
        else if (vDown && v == -1)
        {
            dirVec = Vector3.down;
        }
        else if (hDown && h == -1)
        {
            dirVec = Vector3.left;
        }
        else if (hDown && h == 1)
        {
            dirVec = Vector3.right;
        }


        //Scan Object
        if (Input.GetButtonDown("Jump") && scanObject != null)
        {
            manager.Action(scanObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        //Move Value
        h = manager.isAction ? 0 : Input.GetAxisRaw("Horizontal") + R_Value + L_Value;
        v = manager.isAction ? 0 : Input.GetAxisRaw("Vertical") + U_Value + D_Value;

        //Check Boutton Down & Up
        bool hDown = manager.isAction ? false : Input.GetButton("Horizontal") || r_Down || l_Down;
        bool hUp   = manager.isAction ? false : Input.GetButtonUp("Horizontal") || r_Up || l_Up;
        bool vDown = manager.isAction ? false : Input.GetButton("Vertical") || u_Down || d_Down;
        bool vUp   = manager.isAction ? false : Input.GetButtonUp("Vertical") || u_Up || d_Up;

        //대화창이 켜져있는동안 행동을 막음



        //Check Horizontal Move && Check Vertical Move

        if (hDown)
        {
            isH = true;
            v   = 0;
        }
        else if (hUp || vUp)
        {
            isH = h != 0;
        }

        if (vDown)
        {
            isH = false;
            h   = 0;
        }


        //Animation
        if (anim.GetInteger("hAxisRaw") != h)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("hAxisRaw", (int)h);
        }
        else if (anim.GetInteger("vAxisRaw") != v)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("vAxisRaw", (int)v);
        }
        else
        {
            anim.SetBool("isChange", false);
        }



        //Direction



        if (vDown && v == 1)
        {
            dirVec = Vector3.up;
        }
        else if (vDown && v == -1)
        {
            dirVec = Vector3.down;
        }

        else if (hDown && h == -1)
        {
            dirVec = Vector3.left;
        }
        else if (hDown && h == 1)
        {
            dirVec = Vector3.right;
        }
        else if (h != 0 || v != 0)
        {
            dirVec = new Vector2(h, v);
        }



        //Scan Object
        if (Input.GetButtonDown("Jump"))
        {
            manager.Action(scanObject);
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        //점프
        if (Input.GetButtonDown("Jump") && !isJumping && !manager.isAction)
        {
            isJumping = true;
            rigid.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
            animator.SetBool("isJumping", isJumping);
            audioSource.PlayOneShot(audioClip);
        }

        //좌우 방향키에서 손을 떼면 속도가 천천히 감소해서 정지하게됨.
        if (Input.GetButtonUp("Horizontal"))//Horizontal : 좌 -1, 우 1, 안눌림 0
        {
            //normalized : 벡터의 크기를 1로 만든 상태.
            rigid.velocity = new Vector2(rigid.velocity.normalized.x * 1.0f, rigid.velocity.y);
        }

        //sprite의 방향전환.
        if (Input.GetKeyDown(KeyCode.LeftArrow) && !manager.isAction)//좌
        {
            spriteRenderer.flipX = false;
            dir.x = -1;
        }

        if (Input.GetKeyDown(KeyCode.RightArrow) && !manager.isAction)//우
        {
            spriteRenderer.flipX = true;
            dir.x = 1;
        }


        if (Input.GetButton("Horizontal"))
        {
            isWalking = true;
        }
        else
        {
            isWalking = false;
        }

        if (Mathf.Abs(rigid.velocity.x) < 0.3)//속도가 0일때 false.
        {
            animator.SetBool("isWalking", false);
        }
        else // 나머진 true 반환
        {
            animator.SetBool("isWalking", true);
        }

        if (Input.GetKeyDown(KeyCode.LeftControl) && (scanObject != null || manager.isAction))
        {
            manager.Action(scanObject);
        }

        if (transform.position.y < -10.0f && !isDead)
        {
            isDead = true;
            manager.GameFailed();
        }
    }
Example #4
0
    void Update()
    {
        // Move Value
        h = gameManager.isAction ? 0 : Input.GetAxisRaw("Horizontal") + right_Value + left_Value;
        v = gameManager.isAction ? 0 : Input.GetAxisRaw("Vertical") + up_Value + down_Value;

        // Check Button Down & Up
        bool hDown = gameManager.isAction ? false : Input.GetButtonDown("Horizontal") || right_Down || left_Down;
        bool vDown = gameManager.isAction ? false : Input.GetButtonDown("Vertical") || up_Down || down_Down;
        bool hUp   = gameManager.isAction ? false : Input.GetButtonUp("Horizontal") || right_Up || left_Up;
        bool vUp   = gameManager.isAction ? false : Input.GetButtonUp("Vertical") || up_Up || down_Up;

        // Check Horizontal Move
        if (hDown)
        {
            isHorizonMove = true;
        }
        else if (vDown)
        {
            isHorizonMove = false;
        }
        else if (hUp || vUp)
        {
            isHorizonMove = h != 0;     // AxisRaw 값에 따라 수평, 수직 판단하여 해결
        }
        // Animation
        if (anim.GetInteger("hAxisRaw") != h)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("hAxisRaw", (int)h);
        }
        else if (anim.GetInteger("vAxisRaw") != v)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("vAxisRaw", (int)v);
        }
        else
        {
            anim.SetBool("isChange", false);
        }

        // Direction
        if (vDown && v == 1)
        {
            dirVec = Vector3.up;
        }
        else if (vDown && v == -1)
        {
            dirVec = Vector3.down;
        }
        else if (hDown && h == 1)
        {
            dirVec = Vector3.right;
        }
        else if (hDown && h == -1)
        {
            dirVec = Vector3.left;
        }

        // Scan Object
        if (Input.GetButtonDown("Jump") && scanedObject != null)
        {
            gameManager.Action(scanedObject);
        }

        // Mobile Var Init
        Mobile_UpDownKeyInit();
    }
Example #5
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            switch (collision.gameObject.name)
            {
            case "교실문 (1)":

                Debug.Log("교실문1");
                Scene2.SetActive(false);
                Scene31.SetActive(true);
                player.PlayerReposition(new Vector2(-7.1f, -2.7f));
                break;

            case "교실문 (2)":

                Debug.Log("교실문2");
                Scene2.SetActive(false);
                Scene32.SetActive(true);
                player.PlayerReposition(new Vector2(-7.1f, -2.7f));
                break;


            case "교실문 (3)":

                Debug.Log("교실문3");
                Scene2.SetActive(false);
                Scene33.SetActive(true);
                player.PlayerReposition(new Vector2(-7.1f, -2.7f));
                break;

            case "쓰레기":

                Debug.Log("trash");
                Destroy(collision.gameObject);
                trashCount++;
                if (trashCount == 3)
                {
                    TrashCan.SetActive(true);
                }
                break;

            case "칠판":

                if (PlayerMove.stuffName == "분필")
                {
                    manager.Action(collision.gameObject);

                    // 말풍선 떠있으면 Freeze
                    if (manager.isActive)
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                    }
                    else
                    {
                        // 대화가 끝나고 아이템 얻기
                        rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                        Item newItem = itemManager.GetWordItem(collision.gameObject.GetComponent <ObjectData>().id);
                        if (newItem != null)
                        {
                            Debug.Log("get newItem: " + newItem.itemName);
                            rigid.GetComponent <Inventory>().AddItem(newItem);
                        }

                        collision.gameObject.SetActive(false);
                    }
                }
                else if (PlayerMove.stuffName == "필통")
                {
                    manager.Action(150);

                    // 말풍선 떠있으면 Freeze
                    if (manager.isActive)
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                    }
                    else
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                    }
                }
                else if (PlayerMove.stuffName == "분식")
                {
                    manager.Action(151);

                    // 말풍선 떠있으면 Freeze
                    if (manager.isActive)
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                    }
                    else
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                    }
                }
                break;

            case "철창":
                if (PlayerMove.stuffName == "열쇠")
                {
                    collision.gameObject.SetActive(false);
                }
                break;

            case "고양이":

                if (manager.isActive)
                {
                    manager.Action(collision.gameObject);
                    if (!manager.isActive)
                    {
                        rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                        Item newItem = itemManager.GetWordItem(collision.gameObject.GetComponent <ObjectData>().id);
                        if (newItem != null)
                        {
                            Debug.Log("get newItem: " + newItem.itemName);
                            rigid.GetComponent <Inventory>().AddItem(newItem);
                        }
                    }
                }
                else if (PlayerMove.stuffName == "간식")
                {
                    manager.Action(collision.gameObject);

                    rigid.constraints = RigidbodyConstraints2D.FreezePositionX |
                                        RigidbodyConstraints2D.FreezePositionY |
                                        RigidbodyConstraints2D.FreezeRotation;
                }
                break;
            }
        }

        if (collision.gameObject.name == "벌서는친구")
        {
            if (Input.anyKey)
            {
                Debug.Log("~리셋~");
                stopwatch.Reset();
                stopwatch.Start();
            }

            // 5초가 지나면...
            if (stopwatch.ElapsedMilliseconds > 5000)
            {
                stopwatch.Reset();
                Debug.Log("5초 지남");
                manager.Action(collision.gameObject);

                rigid.constraints = RigidbodyConstraints2D.FreezePositionX |
                                    RigidbodyConstraints2D.FreezePositionY |
                                    RigidbodyConstraints2D.FreezeRotation;
            }

            if (Input.GetKeyDown(KeyCode.W) && manager.isActive)
            {
                manager.Action(collision.gameObject);
                if (!manager.isActive)
                {
                    rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                    Item newItem = itemManager.GetWordItem(collision.gameObject.GetComponent <ObjectData>().id);
                    if (newItem != null)
                    {
                        Debug.Log("get newItem: " + newItem.itemName);
                        rigid.GetComponent <Inventory>().AddItem(newItem);
                    }
                }
            }
        }
    }
Example #6
0
    void Update()
    {
        //Move Value
        h = manager.isAction? 0 : Input.GetAxisRaw("Horizontal");
        v = manager.isAction ? 0 : Input.GetAxisRaw("Vertical");

        //Check Button Down & Up
        bool hDown = manager.isAction ? false : Input.GetButtonDown("Horizontal");
        bool vDown = manager.isAction ? false : Input.GetButtonDown("Vertical");
        bool hUp   = manager.isAction ? false : Input.GetButtonUp("Horizontal");
        bool vUp   = manager.isAction ? false : Input.GetButtonUp("Vertical");

        //Check Horizontal Move
        if (hDown)
        {
            isHorizonMove = true;
        }
        else if (vDown)
        {
            isHorizonMove = false;
        }
        else if (hUp || vUp)
        {
            isHorizonMove = h != 0;
        }


        //Animation
        if (anim.GetInteger("hAxisRaw") != h)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("hAxisRaw", (int)h);
        }
        else if (anim.GetInteger("vAxisRaw") != v)
        {
            anim.SetBool("isChange", true);
            anim.SetInteger("vAxisRaw", (int)v);
        }
        else
        {
            anim.SetBool("isChange", false);
        }

        //Direction
        //상
        if (vDown && v == 1)
        {
            dirVec = Vector3.up;
        }
        //하
        else if (vDown && v == -1)
        {
            dirVec = Vector3.down;
        }
        //좌
        else if (hDown && h == -1)
        {
            dirVec = Vector3.left;
        }
        //우
        else if (hDown && h == 1)
        {
            dirVec = Vector3.right;
        }

        //Scan Object
        if (Input.GetButtonDown("Jump") && scanObject != null) //스페이스바
        {
            manager.Action(scanObject);
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        // Move Value(PC+Mobile)
        h = manager.isAction ? 0 : Input.GetAxisRaw("Horizontal") + right_Value + left_Value; // 더하는 이유는 움직임 상쇄 때문에(동시에 누르면 1 -1 = 0)
        v = manager.isAction ? 0 : Input.GetAxisRaw("Vertical") + up_Value + down_Value;;


        // Check Button Down & Up(PC+Mobile)
        hDown = manager.isAction ? false : Input.GetButtonDown("Horizontal") || right_Down || left_Down;
        vDown = manager.isAction ? false : Input.GetButtonDown("Vertical") || up_Down || down_Down;
        hUp   = manager.isAction ? false : Input.GetButtonUp("Horizontal") || right_Up || left_Up;
        vUp   = manager.isAction ? false : Input.GetButtonUp("Vertical") || up_Up || down_Up;


        // Check Horizontal Move
        if (hDown || vUp)
        {
            // Debug.Log("가로 이어서 이동");
            isHorizonMove = true;
        }
        else if (vDown || hUp)
        {
            // Debug.Log("세로 이어서 이동");
            isHorizonMove = false;
        }
        else if (hUp || vUp)
        {
            // 현재 AxisRaw 값에 따라 수평, 수직 판단하여 해결
            isHorizonMove = h != 0;
        }

        // Animation
        if (anime.GetFloat("hAxisRaw") != h)
        {
            anime.SetBool("isChange", true);
            anime.SetFloat("hAxisRaw", h);
        }
        else if (anime.GetFloat("vAxisRaw") != v)
        {
            anime.SetBool("isChange", true);
            anime.SetFloat("vAxisRaw", v);
        }
        else
        {
            anime.SetBool("isChange", false);
        }

        // Direction
        if (vDown && v == 1)
        {
            dirVec = Vector3.up;
        }
        else if (vDown && v == -1)
        {
            dirVec = Vector3.down;
        }
        else if (hDown && h == 1)
        {
            dirVec = Vector3.right;
        }
        else if (hDown && h == -1)
        {
            dirVec = Vector3.left;
        }

        // Scan Object
        if (Input.GetButtonDown("Jump") && scanObject != null)
        {
            // Debug.Log("this is : " + scanObject.name);
            manager.Action(scanObject);
        }

        // Mobile Var Init - 초기화 작업
        up_Down    = false;
        down_Down  = false;
        left_Down  = false;
        right_Down = false;
        up_Up      = false;
        down_Up    = false;
        left_Up    = false;
        right_Up   = false;
    }
Example #8
0
 public void ActionButton()
 {
     gameManager.Action();
 }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log(TAG + "Update: " + rigid.position);


        /* 얼굴 방향 바꾸기 */
        if (Input.GetButton("Horizontal"))
        {
            //Debug.Log(Input.GetButton("Horizontal"));

            // 왼쪽을 보고 있다가 오른쪽으로 바뀐 경우
            if (!facingRight && Input.GetAxisRaw("Horizontal") > 0)
            {
                spriteRenderer.flipX = !spriteRenderer.flipX;
                facingRight          = true;
            }
            // 오른쪽 보고 있다가 왼쪽으로 바뀐 경우
            else if (facingRight && Input.GetAxisRaw("Horizontal") < 0)
            {
                spriteRenderer.flipX = !spriteRenderer.flipX;
                facingRight          = false;
            }

            // 걷기 애니메이션 적용
            animator.SetBool("isWalking", true);
        }

        /* 미끄럼 없애기 */
        if (Input.GetButtonUp("Horizontal"))
        {
            rigid.velocity = new Vector2(0, rigid.velocity.y);
            animator.SetBool("isWalking", false);
        }

        /* 점프 */
        if (Input.GetButtonDown("Jump") && animator.GetBool("isGround"))
        {
            rigid.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
            animator.SetBool("isGround", false);
        }

        // Scan Object
        if (Input.GetKeyDown("w") && scanObject != null)
        {
            // w키를 누르고, 스캔오브젝트가 널이 아니면 manager의 Action함수 실행
            Debug.Log("W누름: " + scanObject.name);
            manager.Action(scanObject);

            // 말풍선 떠있으면 Freeze
            if (manager.isActive)
            {
                rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
            }
            else
            {
                // 대화가 끝나고 아이템 얻기
                rigid.constraints = RigidbodyConstraints2D.FreezeRotation;
                Item newItem = itemManager.GetWordItem(scanObject.GetComponent <ObjectData>().id);
                if (newItem != null)
                {
                    Debug.Log("get newItem: " + newItem.itemName);
                    rigid.GetComponent <Inventory>().AddItem(newItem);
                }
            }
        }
    }