Example #1
0
        // called by UILevel - fades in a star (int : 1-3)
        public void StarsFade(int starId)
        {
            Debug.Log("starsFade " + starId);
            switch (starId)
            {
            case 1:
                Star1.SetActive(true);
                UILevelselectionManager.StarShake();
                animator.SetTrigger("star1");
                SoundManager.PlayStarGetSound();
                break;

            case 2:
                Star2.SetActive(true);
                UILevelselectionManager.StarShake();
                animator.SetTrigger("star2");
                SoundManager.PlayStarGetSound();
                break;

            case 3:
                Star3.SetActive(true);
                UILevelselectionManager.StarShake();
                animator.SetTrigger("star3");
                SoundManager.PlayStarGetSound();
                break;
            }
        }
        private void Awake()
        {
            if (_instance != null && _instance != this)
            {
                Destroy(this.gameObject);
                return;
            }
            _instance     = this;
            activeUILevel = ProgressManager.GetProgress().storyProgress.lastPlayedLevelID;

            if (enterType != EnterType.none)
            {
                enterType = EnterType.none;
            }
        }
Example #3
0
        private void Update()
        {
            if (collectInput)
            {
                //If running game in editor
#if UNITY_EDITOR
                //If mouse button 0 is down
                if (Input.GetMouseButton(0))
                {
                    Vector2 mouseCache = Input.mousePosition;
                    if (!dragging)
                    {
                        dragBeginPos = mouseCache;
                        dragging     = true;
                    }

                    //claculate the length of the current drag
                    dragLength = (dragBeginPos.x - mouseCache.x) * -1;

                    //Drag is long enough to switch to the next level
                    if (Mathf.Abs(dragLength) >= screenWidth * minScreenWidthPercentToSwitch)
                    {
                        //drag to the right
                        if (dragLength > 0)
                        {
                            if (!UILevelselectionManager.LastLevel())
                            {
                                StartCoroutine(lerpBackToOrigin());
                                SoundManager.PlayUnvalidSound();
                                UILevelselectionManager.StarShake();
                            }
                            else
                            {
                                onBounceBack.Invoke();
                            }
                        }
                        //drag to the left
                        else
                        {
                            if (!UILevelselectionManager.NextLevel())
                            {
                                StartCoroutine(lerpBackToOrigin());
                                SoundManager.PlayUnvalidSound();
                                UILevelselectionManager.StarShake();
                            }
                            else
                            {
                                onBounceBack.Invoke();
                            }
                        }
                    }
                    newDragObjectPos = new Vector3(defaultPosition.x + dragLength, defaultPosition.y, defaultPosition.z);
                    //Debug.Log(dragLength + " " + originDragObjectPos.x);
                    touched = true;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    Vector2 mouseCache = Input.mousePosition;
                    dragging = false;

                    if (dragLength <= screenWidth * minScreenWidthPercentToSwitch)
                    {
                        StartCoroutine(lerpBackToOrigin());
                        if (dragLength > 20 || dragLength < -20)
                        {
                            onBounceBack.Invoke();
                        }
                    }
                }
#endif
                //If a touch is detected
                if (Input.touchCount >= 1)
                {
                    Touch   touch      = Input.touches[0];
                    Vector2 touchCache = touch.position;

                    //finger is on screen
                    if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                    {
                        if (!dragging)
                        {
                            dragBeginPos = touchCache;
                            dragging     = true;
                        }

                        //claculate the length of the current drag
                        dragLength = (dragBeginPos.x - touchCache.x) * -1;

                        //Drag is long enough to switch to the next level
                        if (Mathf.Abs(dragLength) >= screenWidth * minScreenWidthPercentToSwitch)
                        {
                            //drag to the right
                            if (dragLength > 0)
                            {
                                if (!UILevelselectionManager.LastLevel())
                                {
                                    StartCoroutine(lerpBackToOrigin());
                                    SoundManager.PlayUnvalidSound();
                                    UILevelselectionManager.StarShake();
                                }
                                else
                                {
                                    onBounceBack.Invoke();
                                }
                            }
                            //drag to the left
                            else
                            {
                                if (!UILevelselectionManager.NextLevel())
                                {
                                    StartCoroutine(lerpBackToOrigin());
                                    SoundManager.PlayUnvalidSound();
                                    UILevelselectionManager.StarShake();
                                }
                                else
                                {
                                    onBounceBack.Invoke();
                                }
                            }
                        }
                        newDragObjectPos = new Vector3(defaultPosition.x + dragLength, defaultPosition.y, defaultPosition.z);
                        touched          = true;
                    }

                    //finger got released
                    else if (touch.phase == TouchPhase.Ended)
                    {
                        dragging = false;

                        if (dragLength <= screenWidth * minScreenWidthPercentToSwitch)
                        {
                            StartCoroutine(lerpBackToOrigin());
                            if (dragLength > 20 || dragLength < -20)
                            {
                                onBounceBack.Invoke();
                            }
                        }
                    }
                }
            }
        }