Exemplo n.º 1
0
    private void Update()
    {
        float iValue = anim.GetFloat("Blend");
        float tValue = selected / selectionMax;

        // Move animator towards selected value
        anim.SetFloat("Blend", Mathf.Lerp(iValue, tValue, Time.smoothDeltaTime * Speed));

        // Check if close enough to selected to keep moving
        closeEnough = Mathf.Abs(tValue - iValue) <= 0.05f;

        if (!active)
        {
            return;
        }

        #region INPUT HANLDING
        float input1 = Player.Get(1).GetAxis("Horizontal", true);
        float input2 = Player.Get(2).GetAxis("Horizontal", true);

        if (input1 != 0)
        {
            MoveMode((int)input1);
        }
        else
        if (input2 != 0)
        {
            MoveMode((int)input2);
        }
        #endregion
    }
    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);
    }