Exemplo n.º 1
0
        /// <summary>Sets the weapon that are in the Inventory</summary>
        /// <param name="Next_Weapon">Game object that it should have an IMWeapon Interface</param>
        public virtual void SetWeaponByInventory(GameObject Next_Weapon)
        {
            if (!Rider.IsRiding)
            {
                return;                                                          //Work Only when is riding else Skip
            }
            if (UseHolders)
            {
                return;                                                         //Work Only when is riding else Skip
            }
            if (WeaponAction != WA.Idle && WeaponAction != WA.None &&
                WeaponAction != WA.AimLeft && WeaponAction != WA.AimRight && WeaponAction != WA.Hold)
            {
                return;                                                                                            //If is not on any of these states then Dont Equip..
            }
            StopAllCoroutines();

            if (Next_Weapon == null)                                    //That means Store the weapon
            {
                if (ActiveWeaponGameObject)
                {
                    Store_Weapon();
                }
                if (debug)
                {
                    Debug.Log("Active Weapon NOT NULL Store the Active Weapon");
                }
                return;
            }

            IMWeapon Next_IMWeapon = Next_Weapon.GetComponent <IMWeapon>();

            if (Next_IMWeapon == null)
            {
                if (ActiveWeaponGameObject)
                {
                    Store_Weapon();
                }
                if (debug)
                {
                    Debug.Log("Active Weapon NOT NULL and Store because  Next Weapon is not Compatible");
                }
                return;                                                 //If the Next Weapon doesnot have the IMWeapon Interface dismiss... the next weapon is not compatible
            }

            if (ActiveWeapon == null)                               //Means there's no weapon active so draw it
            {
                if (!AlreadyInstantiated)
                {
                    Next_Weapon = Instantiate(Next_Weapon, Rider.transform);    //Instanciate the Weapon GameObject
                    Next_Weapon.SetActive(false);                               //Hide it to show it later
                    if (debug)
                    {
                        Debug.Log("<B>" + Next_Weapon.name + "</B> Instantiated");
                    }
                }
                ActiveWeaponGameObject = Next_Weapon;

                Draw_Weapon();                                                  //Debug.Log("Active weapon is NULL so DRAW");
            }
            else if (ActiveWeapon.Equals(Next_IMWeapon))                        //You are trying to draw the same weapon
            {
                if (!CombatMode)
                {
                    Draw_Weapon();
                    Debug.Log("Active weapon is the same as the NEXT Weapon and we are NOT in Combat so DRAW");
                }
                else
                {
                    Store_Weapon();
                    if (debug)
                    {
                        Debug.Log("Active weapon is the same as the NEXT Weapon and we ARE  in Combat so STORE");
                    }
                }
            }
            else                                                                //If the weapons are different Swap it
            {
                StartCoroutine(SwapWeaponsInventory(Next_Weapon));
                if (debug)
                {
                    Debug.Log("Active weapon is DIFFERENT to the NEXT weapon so Switch" + Next_Weapon);
                }
            }
        }