예제 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.CompareTag("Field"))
        {
            if (effectImg != null)
            {
                for (int index = 0; index < effectImg.transform.childCount; index++)
                {
                    // -> Electric
                    ElectricShow eShow = effectImg.transform.GetChild(index).GetComponent <ElectricShow>();
                    if (eShow != null)
                    {
                        effectImg.SetActive(true);
                        eShow.ChargeLighting();
                    }
                }
            }
        }

        else if (collision.collider.CompareTag("FallBorder"))
        {
            if (!fallen)
            {
                Defeated();
                fallen = true;
            }

            if (PlayerPrefs.GetString("InstructionShowed", "n") == "n")
            {
                GameObject.FindGameObjectWithTag("GMScript").GetComponent <PlrPrefsCtrl>().OutGamePlay();
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!MainCtrlManager.GamePaused)
        {
            // Set rigidbody to dynamic so that it falls down
            if (rb.bodyType != RigidbodyType2D.Dynamic)
            {
                rb.bodyType = RigidbodyType2D.Dynamic;

                // Dissolve back to initial state
                fadeCoefficient = 0;
                for (int index = 0; index < dissolves.Length; index++)
                {
                    dissolves[index].SetFloat("_Fade", fadeCoefficient);
                }

                Invoke("MoveAnimation", 0.5f);
                particleExp.SetActive(false);
            }

            // Stabilize character
            transform.rotation = Quaternion.identity;

            // Avoid being pushed left and right
            rb.velocity = new Vector3(0, rb.velocity.y, 0);

            // Shapeshifting and jumping by key arrows__________________________
            if (Input.GetKey(KeyCode.UpArrow) && instructionShowed)
            {
                Jump();
            }

            else if (Input.GetKey(KeyCode.RightArrow) && instructionShowed)
            {
                if (currentShapeID != 0)
                {
                    ShapeShift(0, false);
                }
            }

            else if (Input.GetKey(KeyCode.DownArrow) && instructionShowed)
            {
                if (currentShapeID != 1)
                {
                    ShapeShift(1, false);
                }
            }

            else if (Input.GetKey(KeyCode.LeftArrow) && instructionShowed)
            {
                if (currentShapeID != 2)
                {
                    ShapeShift(2, false);
                }
            }

            // Shapeshifting and jumping by swipe_______________________________
            if (Input.touchCount > 0 && instructionShowed)
            {
                Touch touch = Input.GetTouch(0);

                switch (touch.phase)
                {
                case TouchPhase.Began:
                    startSwipePosition = touch.position;
                    break;

                case TouchPhase.Ended:
                    endSwipePosition = touch.position;
                    ActAccordingToSwipe(DecideSwipeDirection(startSwipePosition, endSwipePosition));
                    break;
                }
            }
            // _________________________________________________________________

            if (jumping && IsGrounded())
            {
                animator.SetTrigger("Move");
                jumping = false;
            }

            // This section is PRIVATE to some of the characters________________

            if (effectImg != null)
            {
                // -> Electric
                for (int index = 0; index < effectImg.transform.childCount; index++)
                {
                    ElectricShow eShow = effectImg.transform.GetChild(index).GetComponent <ElectricShow>();
                    if (eShow != null)
                    {
                        if (Mathf.Abs(rb.velocity.y) >= 0.5f)
                        {
                            eShow.StopLighting();
                            effectImg.SetActive(false);
                        }
                    }
                }

                // -> Forest
                if (!effectImg.activeSelf && effectImg.transform.childCount == 1)
                {
                    effectImg.SetActive(true);
                }
            }
        }

        else if (!MainCtrlManager.GameStarted)
        {
            // Set rigidbody to static so that it does not fall down
            if (!fusionInitiated)
            {
                rb.bodyType = RigidbodyType2D.Static;
                particleFusion.SetActive(true);
                Invoke("SquareGlow", 5.001f);
                fusionInitiated = true;
            }

            // Only call if fusion is not completed
            if (fadeCoefficient < 1f)
            {
                ShapeFusion();
            }
        }

        else
        {
            if (rb.bodyType != RigidbodyType2D.Static)
            {
                rb.bodyType = RigidbodyType2D.Static;
            }
        }
    }