Esempio n. 1
0
    public void MoveMode(int dir)
    {
        if (!closeEnough)
        {
            return;
        }
        selected += dir;

        // Below lower bound
        if (selected == -1)
        {
            float lastModeValue = (selectionMax - 1f) / selectionMax;
            anim.SetFloat("Blend", lastModeValue);
            selected = (int)selectionMax - 2;
        }
        else
        // Above higher bound
        if (selected == selectionMax + 1)
        {
            anim.SetFloat("Blend", 1f / selectionMax);
            selected = 2;
        }

        // Correct selected mode (for helpers)
        if (selected == 0)
        {
            selectedMode = Game.Modes.WizardWeather;
        }
        else if (selected == selectionMax)
        {
            selectedMode = Game.Modes.Lobby;
        }
        else
        {
            selectedMode = (Game.Modes)selected;
        }

        // Disable slider if selecting tutorial
        if (selectedMode == Game.Modes.Lobby)
        {
            slider.transform.parent.gameObject.SetActive(false);
        }
        else
        {
            slider.transform.parent.gameObject.SetActive(true);
        }
    }
    private void Update()
    {
        #region INPUT HANDLING
        if (active)
        {
            // Move with horizontal axis
            if (Owner != null)
            {
                Move();
            }

            // Get ready
            if (closeEnough && anim.GetBool("NameSet"))
            {
                if (Owner.GetButton("Dash", consume: false))
                {
                    anim.SetBool("Ready", true);

                    // If both are ready
                    if (other.anim.GetBool("Ready"))
                    {
                        // Save names
                        Owner.name       = userName.text;
                        other.Owner.name = other.userName.text;

                        // Save player selection into their owners
                        Owner.playingAs       = showcase[selected].ID;
                        other.Owner.playingAs = other.showcase[other.selected].ID;

                        // Notify that players are ready
                        Lobby.charactersSelected = true;

                        // De-activate both selectors
                        SwitchState(state: false);
                        other.SwitchState(state: false);
                    }
                }
            }
        }
        #endregion

        #region MOVING TO POSITION
        // Move towards selected character
        var tPos = showcase[selected].transform.position;
        transform.position = Vector3.Lerp(transform.position, tPos, Time.deltaTime * Speed);
        // Check if close enough to selected to keep moving
        closeEnough = Vector3.Distance(tPos, transform.position) <= 0.4f;

        // Move animator towards selected value
        float iValue = anim.GetFloat("Blend");
        float tValue = selected / 3f;
        anim.SetFloat("Blend", Mathf.Lerp(iValue, tValue, Time.deltaTime * Speed));
        #endregion

        // Make info face camera
        canvas.LookAt(cam);
    }