コード例 #1
0
ファイル: UnitControl.cs プロジェクト: Diggery/CyberOps
    public bool AddWeapon(string weaponName, int mags)
    {
        if (string.IsNullOrEmpty(weaponName))
        {
            return(false);
        }

        if (!AttachRightBack)
        {
            Debug.Log("Missing an attachPoint");
            return(false);
        }

        Debug.Log("Getting " + weaponName + " for " + gameObject.name);
        GameObject weaponObj = gameManager.GetEquipment(weaponName);

        if (!weaponObj)
        {
            return(false);
        }

        Weapon weapon = weaponObj.GetComponent <Weapon>();

        weaponObj.transform.SetParent(AttachRightBack, false);

        if (weapon)
        {
            weapon.Init(this);
            unitAttack.AddWeapon(weapon, !weapon.isSecondary);
            unitAttack.DrawWeapon(weapon);

            WeaponRanged weaponRanged = weaponObj.GetComponent <WeaponRanged>();
            if (weaponRanged)
            {
                weaponRanged.AddMagazines(mags);
            }

            if (weapon.animOverride)
            {
                animator.runtimeAnimatorController = weapon.animOverride;
            }
        }
        else
        {
            return(false);
        }
        return(true);
    }