コード例 #1
0
ファイル: WeaponBody.cs プロジェクト: Lomztein/Microsquad
    public void BuildWeapon()
    {
        // Yeah this is pretty shit. It'll do, though.

        if (isBuild) {
            Debug.LogError ("Tried building already build weapon.");
            return;
        }

        weapon = transform.parent.GetComponent<Weapon>();

        if (barrelPrefab) {
            weapon.muzzles = new Transform[barrelAttachmentPoint.Length];
            weapon.barrels = new WeaponBarrel[barrelAttachmentPoint.Length];
            for (int i = 0; i < barrelAttachmentPoint.Length; i++) {
                GameObject b = (GameObject)Instantiate (barrelPrefab, barrelAttachmentPoint[i].position, Quaternion.identity);
                barrel = b.GetComponent<WeaponBarrel>();
                barrel.transform.parent = barrelAttachmentPoint[i];
                weapon.barrels[i] = barrel;
                weapon.muzzles[i] = barrel.muzzle;
                weapon.weaponParts.Add (barrel);
            }
        }
        if (stockPrefab && stockAttachmentPoint) {
            GameObject s = (GameObject)Instantiate (stockPrefab, stockAttachmentPoint.position, Quaternion.identity);
            stock = s.GetComponent<WeaponStock>();
            stock.transform.parent = stockAttachmentPoint;
            weapon.weaponParts.Add (stock);
        }
        if (opticPrefab && opticsAttachmentPoint) {
            GameObject o = (GameObject)Instantiate (opticPrefab, opticsAttachmentPoint.position, Quaternion.identity);
            optic = o.GetComponent<WeaponOptic>();
            optic.transform.parent = opticsAttachmentPoint;
            weapon.weaponParts.Add (optic);
        }
        if (underBarrelPrefab && underBarrelAttachmentPoint) {
            GameObject ub = (GameObject)Instantiate (underBarrelPrefab, underBarrelAttachmentPoint.position, Quaternion.identity);
            underBarrel = ub.GetComponent<WeaponUnderbarrelAttachment>();
            underBarrel.transform.parent = underBarrelAttachmentPoint;
            weapon.weaponParts.Add (underBarrel);
        }
        if (magazinePrefab) {
            GameObject ma = (GameObject)Instantiate (magazinePrefab, magazineAttachmentPoint.position, Quaternion.identity);
            magazine = ma.GetComponent<WeaponMagazine>();
            magazine.transform.parent = magazineAttachmentPoint;
            weapon.weaponParts.Add (magazine);
        }

        weapon.CombineData ();
        isBuild = true;
    }
コード例 #2
0
ファイル: Map.cs プロジェクト: redcommand025/Smod2
 public abstract void SpawnItem(WeaponType type, float Ammo, WeaponSight Sight, WeaponBarrel Barrel, WeaponOther Other, Vector pos, Vector rotation);