Пример #1
0
    public bool Equip(WeaponItem.Type type, bool forceUpdate = false)
    {
        if (type == equipedItem.type && !forceUpdate)
        {
            return(true);
        }

        if (type != WeaponItem.Type.None)
        {
            WeaponItem newItem = Arsenal.Instance.Get(type);
            if (newItem)
            {
                MeshFilter mf = newItem.GetComponent <MeshFilter>();
                if (mf)
                {
                    equipedMesh.mesh = mf.mesh;
                    WeaponItem.Copy(newItem, equipedItem);
                    return(true);
                }
            }
        }
        equipedItem.Clear();
        equipedMesh.mesh = null;
        return(false);
    }
Пример #2
0
    public void EquipItem(Item item)
    {
        if (PlayerState.instance.inventoryStock.GetItem(item))
        {
            switch (((WeaponItem)item).wieldType)
            {
            case WieldType.MainHand:
                if (mainWeaponObject)
                {
                    Destroy(mainWeaponObject.gameObject);
                }

                mainWeaponObject = Instantiate((WeaponItem)item, transform);
                mainWeaponObject.transform.position    = nodes.GetPosition(0);
                mainWeaponObject.transform.eulerAngles = new Vector3(0f, 0f, nodes.GetAngle(0));
                mainWeaponObject.GetComponent <SpriteRenderer>().sortingOrder = -1;
                break;

            case WieldType.OffHand:
                if (offWeaponObject)
                {
                    Destroy(offWeaponObject.gameObject);
                }

                offWeaponObject = Instantiate((WeaponItem)item, transform);
                offWeaponObject.transform.position    = nodes.GetPosition(1);
                offWeaponObject.transform.eulerAngles = new Vector3(0f, 0f, nodes.GetAngle(1));
                offWeaponObject.GetComponent <SpriteRenderer>().sortingOrder = 2;
                break;

            case WieldType.TwoHand:
                if (mainWeaponObject)
                {
                    Destroy(mainWeaponObject.gameObject);
                }

                if (offWeaponObject)
                {
                    Destroy(offWeaponObject.gameObject);
                }
                break;
            }
        }
    }
Пример #3
0
    public void UseWeapon(WeaponItem weapon)
    {
        if (currentWeapon == weapon)
        {
            if (weapoIsActive)
            {
                //Снять оружие за спину
                weapoIsActive = false;
                currentWeapon.transform.SetParent(backT);
                currentWeapon.gameObject.transform.localPosition = currentWeapon.weaponBackPos;
                currentWeapon.gameObject.transform.localRotation = Quaternion.Euler(currentWeapon.weaponBackRot);

                WeaponDamage wd = currentWeapon.GetComponent <WeaponDamage>();
                if (wd != null)
                {
                    wd.thisPlayerWeapon = true;
                }

                //Анимация + блокировка бега
                battleMode = false;
                myAnimator.SetTrigger("OffBattleMode");
                //myAnimator.SetFloat("speed", 0);
                //StartCoroutine(SetMoveBlock(0.88f));
            }
            else
            {
                //Взять оружие в руку
                weapoIsActive = true;
                currentWeapon.transform.SetParent(rHandT);
                currentWeapon.gameObject.transform.localPosition = currentWeapon.weaponRHandPos;
                currentWeapon.gameObject.transform.localRotation = Quaternion.Euler(currentWeapon.weaponRHandRot);

                WeaponDamage wd = currentWeapon.GetComponent <WeaponDamage>();
                if (wd != null)
                {
                    wd.thisPlayerWeapon = true;
                }

                //Анимация + блокировка бега

                //myAnimator.SetFloat("speed", 0);
                myAnimator.SetTrigger("OnBattleMode");
                battleMode = true;
                //StartCoroutine(SetMoveBlock(0.88f));
            }
        }
        else
        {
            //Одеть первый раз за спину
            if (currentWeapon != null)
            {
                currentWeapon.gameObject.SetActive(false);
            }
            currentWeapon = weapon;
            currentWeapon.gameObject.SetActive(true);
            weapoIsActive = false;
            currentWeapon.transform.SetParent(backT);
            currentWeapon.gameObject.transform.localPosition = currentWeapon.weaponBackPos;
            currentWeapon.gameObject.transform.localRotation = Quaternion.Euler(currentWeapon.weaponBackRot);
        }
    }