Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        // get pick up item input
        if (InputMgr.GetButton((int)m_input.m_nbPlayer, InputMgr.eButton.GRAB) && !IsGrabing)
        {
            if (WeaponList.Count > 0)
            {
                PickupWeapon();
            }
        }
        IsGrabing = InputMgr.GetButton((int)m_input.m_nbPlayer, InputMgr.eButton.GRAB);

        switch (m_attack.EquipWeap)
        {
        case PlayerAttack.eWeapon.Pistol:
            m_weapon.PickPistol();
            break;

        case PlayerAttack.eWeapon.Saber:
            m_weapon.PickSaber();
            break;

        default:
            m_weapon.Drop();
            break;
        }
    }
 // ======================================================================================
 // PROTECTED MEMBERS
 // ======================================================================================
 override protected void UpdatePhase()
 {
     // reset triggers when button released
     m_dashTrigger   = !InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.DASH) || m_dashTrigger;
     m_jumpTrigger   = !InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.JUMP) || m_jumpTrigger;
     m_grabTrigger   = !InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.GRAB) || m_grabTrigger;
     m_tossTrigger   = !InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.TOSS) || m_tossTrigger;
     m_attackTrigger = !InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.ATTACK) || m_attackTrigger;
 }
    // ======================================================================================
    override public bool GetGrab()
    {
        if (m_grabTrigger && InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.GRAB))
        {
            m_grabTrigger = false;
            return(true);
        }

        return(false);
    }
    // ======================================================================================
    override public bool GetAttack()
    {
        if (m_attackTrigger && InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.ATTACK))
        {
            m_attackTrigger = false;
            return(true);
        }

        return(false);
    }
    // ======================================================================================
    override public bool GetToss()
    {
        if (m_tossTrigger && InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.TOSS))
        {
            m_tossTrigger = false;
            return(true);
        }

        return(false);
    }
    // ======================================================================================
    override public bool GetJump()
    {
        if (m_jumpTrigger && InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.JUMP))
        {
            m_jumpTrigger = false;
            return(true);
        }

        return(false);
    }
    // ======================================================================================
    override public bool GetDash()
    {
        if (m_dashTrigger && InputMgr.GetButton((int)m_nbPlayer, InputMgr.eButton.DASH))
        {
            m_dashTrigger = false;
            return(true);
        }

        return(false);
    }
    // ======================================================================================
    public void Update()
    {
#if UNITY_EDITOR
        m_useAnimation = m_animator != null;

        if (!Application.isPlaying)
        {
            return;
        }
#endif
        if (GameMgr.IsGameOver)
        {
            return;
        }

        float horizontal = 0, vertical = 0;
        bool  doJump = false, doDash = false;

        if (!isStunned)
        {
            // get input
            horizontal = InputMgr.GetAxis((int)m_player, InputMgr.eAxis.HORIZONTAL);          //Input.GetAxis("Horizontal");
            vertical   = InputMgr.GetAxis((int)m_player, InputMgr.eAxis.VERTICAL);            //Input.GetAxis("Vertical");
            doJump     = InputMgr.GetButton((int)m_player, InputMgr.eButton.JUMP);            //Input.GetButtonDown("Jump");
            doDash     = InputMgr.GetButton((int)m_player, InputMgr.eButton.DASH);            //Input.GetButtonDown("Dash");

            // get pick up item input
            if (InputMgr.GetButton((int)m_player, InputMgr.eButton.GRAB) && !grabButtonPressed)
            {
                if (WeaponList.Count > 0)
                {
                    PickupWeapon();
                }
            }
            grabButtonPressed = InputMgr.GetButton((int)m_player, InputMgr.eButton.GRAB);

            // get throw item input
            if (InputMgr.GetButton((int)m_player, InputMgr.eButton.TOSS))
            {
                if (EquippedWeapon != WeaponPickup.WeaponType.FISTS)
                {
                    ThrowWeapon();
                }
            }

            // get attack input
            if (InputMgr.GetButton((int)m_player, InputMgr.eButton.ATTACK) && !isAttacking)
            {
                isAttacking = true;
                switch (EquippedWeapon)
                {
                case WeaponPickup.WeaponType.FISTS:
                    PunchAttack();
                    break;

                case WeaponPickup.WeaponType.SABER:
                    SaberAttack();
                    break;

                case WeaponPickup.WeaponType.PISTOL:
                    PistolAttack();
                    break;
                }
            }
        }

        // update position
        UpdateTransform(horizontal, vertical, doJump, doDash);



        // OBS: UptadeAnimator MAYBE is OUT OF DATE!!!!
        // TODO: Test with anims and update if necessary
        if (m_useAnimation)
        {
            m_animator.SetState(m_state);
            m_animator.SetDirection(m_direction);
        }
    }