Beispiel #1
0
    public void EquipWeapon(string weapon, int weapPos)
    {
        Destroy(weapons[weapPos]);
        Vector3 p = new Vector3(hands[weapPos % 2].position.x, hands[weapPos % 2].position.y - 0.4f, hands[weapPos % 2].position.z);

        weapons [weapPos] = Instantiate(Resources.Load(weapon) as GameObject, p, transform.rotation) as GameObject;
        switch (weapon)
        {
        case "APS403": {
            weaponScripts[weapPos] = new APS403();
            weapons[weapPos].transform.Rotate(0f, 0f, 8f * ((weapPos % 2) == 0 ? -1 : 1));
            break;
        }

        case "SHL009": {
            weaponScripts[weapPos] = new SHL009();
            float rot = -165;
            weapons[weapPos].transform.rotation = Quaternion.Euler(new Vector3(90, rot, 0));
            break;
        }

        case "SHS309": {
            weaponScripts[weapPos] = new SHS309();
            weapons[weapPos].transform.Rotate(0, 0, (weapPos % 2 == 0 ? -1 : 0) * 180);
            weapons[weapPos].transform.position = new Vector3(p.x, p.y + 0.8f, p.z + 0.5f);
            break;
        }
        }
        weapons [weapPos].transform.SetParent(hands [weapPos % 2]);
        if (weapPos >= 2)
        {
            weapons[weapPos].SetActive(false);
        }
    }
Beispiel #2
0
    private void buildWeapons(string[] weaponNames)
    {
        if (weapons != null)
        {
            for (int i = 0; i < weapons.Length; i++)
            {
                if (weapons[i] != null)
                {
                    Destroy(weapons[i]);
                }
            }
        }
        weapons       = new GameObject[4];
        weaponScripts = new Weapon[4];
        for (int i = 0; i < weaponNames.Length; i++)
        {
            Vector3 p = new Vector3(hands[i % 2].position.x, hands[i % 2].position.y - 0.4f, hands[i % 2].position.z);
            weapons [i] = Instantiate(Resources.Load(weaponNames [i]) as GameObject, p, transform.rotation) as GameObject;

            switch (weaponNames[i])
            {
            case "APS403": {
                weaponScripts[i] = new APS403();
                weapons[i].transform.Rotate(0f, 0f, 8f * ((i % 2) == 0 ? -1 : 1));
                break;
            }

            case "SHL009": {
                weaponScripts[i] = new SHL009();
                float rot = -135;
                weapons[i].transform.rotation = Quaternion.Euler(new Vector3(90, ((i % 2) == 0?rot - 60:rot), 0));
                weapons[i].transform.position.Set(p.x, p.y, p.z);
                break;
            }

            case "SHS309": {
                weaponScripts[i] = new SHS309();
                weapons[i].transform.Rotate(0, 0, (i % 2 == 0 ? -1 : 0) * 180);
                weapons[i].transform.position = new Vector3(p.x + ((i % 2) == 0 ? 0 : 1) * 0.25f, p.y + 0.8f, p.z + 0.5f);
                break;
            }
            }
            weapons [i].transform.SetParent(hands [i % 2]);
        }
        weaponOffset = 0;
        weapons [2].SetActive(false);
        weapons [3].SetActive(false);
    }