Example #1
0
    public void SwapWeapon()        //For PC
    {
        for (int i = 0; i < m_Data.m_Weapons.Count; i++)
        {
            //find Weapon in hand in weapon list
            Weapon _weap = m_Data.m_Weapons[i];
            if (_weap.gameObject.activeInHierarchy)
            {
                m_Ani.SetTrigger("WeaponSwap");

                m_Data.m_WeaponInhand.gameObject.SetActive(false);

                //if index of weapon in hand is last index of weapon list, change current weapon to weapon with code 0.
                if (i == m_Data.m_Weapons.Count - 1)
                {
                    m_Data.m_WeaponInhand = m_Data.m_Weapons[0];

                    m_Ani.SetInteger("Weapon_Code", 0);
                    gameObject.SendMessage("PlaySound", (int)(SOUNDCLIP.SWAP), 0);
                }
                //change current weapon to weapon with next code.
                else
                {
                    m_Data.m_WeaponInhand = m_Data.m_Weapons[i + 1];

                    m_Ani.SetInteger("Weapon_Code", i + 1);
                    gameObject.SendMessage("PlaySound", (int)(SOUNDCLIP.SWAP), 0);
                }
                m_Data.m_WeaponInhand.gameObject.SetActive(true);

                //If the weapon is sniper, move camera position
                if (m_Data.m_WeaponInhand.m_ObjName == "Sniper")
                {
                    m_CameraMove.CameraLerp(CAMERAPOS.SNIPER_SHOOTPOS);
                }
                else
                {
                    m_CameraMove.CameraLerp(CAMERAPOS.NORMALPOS);
                }

                //if player was reloading, cancel relaoding.
                if (m_Data.m_isReloading == true)
                {
                    m_Data.m_isReloading = false;
                    m_Ani.SetBool("'Bool", false);
                }

                //Set bool.
                m_Data.m_isSwaping = true;
                m_Ani.SetBool("Swap_b", m_Data.m_isSwaping);
                CancelInvoke("SetSwapingFalse");
                Invoke("SetSwapingFalse", 1f);

                //Set IK Position
                m_AimIK.SetHandsIKPosition(m_Data.m_WeaponInhand.m_GrabPosRight, m_Data.m_WeaponInhand.m_GrabPosLeft);

                //Set Speed
                m_Data.m_Speed = m_Data.m_MaxSpeed - m_Data.m_WeaponInhand.m_Weight;

                break;
            }
        }
    }