Esempio n. 1
0
    private void Update()
    {
        if (IsGrounded() && Input.GetKeyDown(KeyCode.Space)) // Jump
        {
            m_Animator.SetBool("m_Jump", true);

            // Add anim for jump

            if (!m_Hide)
            {
                if (m_OnPogostick)
                {
                    GetComponent <AudioSource>().PlayOneShot(pogoSound, 1.0f);
                    m_Rigidbody2D.AddForce(new Vector2(0, m_JumpForcePogo));
                    m_OnPogostick = false;
                }
                else
                {
                    m_Rigidbody2D.AddForce(new Vector2(0, m_JumpForce));
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.S) && !m_Hide && handRight == null) // Hide
        {
            m_Hide    = true;
            handRight = Instantiate <HandBehaviour>(m_HandPrefab, new Vector3(6.8f, -10.0f, -5.0f), new Quaternion());
            handLeft  = Instantiate <HandBehaviour>(m_HandPrefab, new Vector3(-6.8f, -10.0f, -5.0f), Quaternion.Euler(0, 180.0f, 0));
        }

        if (Input.GetKeyUp(KeyCode.S) && m_Hide) // Show
        {
            m_Hide = false;
            StartCoroutine(handRight.Disappear());
            StartCoroutine(handLeft.Disappear());
        }
        if (m_Hide && m_handCooldown == 300)
        {
            m_Hide = false;
            StartCoroutine(handRight.Disappear());
            StartCoroutine(handLeft.Disappear());
            m_handCooldown = 0;
        }
        if (m_Hide)
        {
            m_handCooldown++;
        }

        if (m_ToysPrefab != null && Input.GetMouseButtonDown(0) && !m_UsedToys[m_IndexToy])
        {
            if (m_ToysPrefab[m_IndexToy].name == "Pogostick")
            {
                m_OnPogostick          = true;
                m_UsedToys[m_IndexToy] = true;
            }
            else
            {
                if (m_FacingRight)
                {
                    Flip();
                }

                Toy toy = Instantiate(m_ToysPrefab[m_IndexToy]);
                toy.CharacterController = this;
                m_UsedToys[m_IndexToy]  = true;

                m_Animator.SetBool("m_Throw", true);

                Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), toy.GetComponent <BoxCollider2D>());

                Vector3 newPos = transform.position;
                newPos.z = 5.0f;
                toy.transform.position = newPos;
                toy.LaunchLeft();

                m_Animator.SetBool("m_Throw", false);
            }
        }

        if (m_ToysPrefab != null && Input.GetMouseButtonDown(1) && !m_UsedToys[m_IndexToy])
        {
            if (m_ToysPrefab[m_IndexToy].name == "Pogostick")
            {
                m_OnPogostick          = true;
                m_UsedToys[m_IndexToy] = true;
            }
            else
            {
                if (!m_FacingRight)
                {
                    Flip();
                }

                Toy toy = Instantiate(m_ToysPrefab[m_IndexToy]);
                toy.CharacterController = this;
                m_UsedToys[m_IndexToy]  = true;

                m_Animator.SetBool("m_Throw", true);

                Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), toy.GetComponent <BoxCollider2D>());

                Vector3 newPos = transform.position;
                newPos.z = 5.0f;
                toy.transform.position = newPos;
                toy.LaunchRight();
            }
        }

        if (m_ToysPrefab != null)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                m_IndexToy = 0;
            }

            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                m_IndexToy = 1;
            }

            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                m_IndexToy = 2;
            }

            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                m_IndexToy = 3;
            }

            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                m_IndexToy = 4;
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }

            if (Input.GetAxis("Mouse ScrollWheel") != 0)
            {
                int updateIndex = (int)(Input.GetAxis("Mouse ScrollWheel") * 10 % 3);
                m_IndexToy += updateIndex;

                if (m_IndexToy < 0)
                {
                    m_IndexToy = m_ToysPrefab.Length - 1;
                }
                else if (m_IndexToy > m_ToysPrefab.Length - 1)
                {
                    m_IndexToy = 0;
                }
            }

            if (m_UIBag != null)
            {
                m_UIBag.ChangedToy(m_IndexToy, m_UsedToys[m_IndexToy]);
            }
        }
    }