Exemplo n.º 1
0
    public GunPositions returnPositions()
    {
        GunPositions currentGuns = new GunPositions();

        currentGuns.scopePosition       = scopePosition;
        currentGuns.barrelPosition      = barrelPosition;
        currentGuns.clipPosition        = clipPosition;
        currentGuns.underBarrelPosition = underBarrelPosition;
        return(currentGuns);
    }
Exemplo n.º 2
0
    public void SpawnGun(GameObject mPlayerInteracting, Transform mParentObject)
    {
        GunValues currentGun = Gun.ReturnGunValues();

        SpawnedGun = Instantiate(typesOfGuns[currentGun.TYPE].ReturnBody(), spawnPos, Quaternion.identity);

        IWeapon      currentWeaponInterface = (IWeapon)SpawnedGun.GetComponent(typeof(IWeapon));
        GunPositions currentGunPos          = currentWeaponInterface.returnPositions();
        GameObject   ScopeObj       = currentGunPos.scopePosition;
        GameObject   underBarrelObj = currentGunPos.underBarrelPosition;
        GameObject   ClipObj        = currentGunPos.clipPosition;
        GameObject   barrelObj      = currentGunPos.barrelPosition;

        GameObject currentGunComponent;
        List <SCR_WeaponPartsClass> scopes = typesOfGuns[currentGun.TYPE].scopes;

        if (scopes[currentGun.SCOPE].ReturnPart())
        {
            Destroy(ScopeObj.transform.GetChild(0).gameObject);
            currentGunComponent = Instantiate(scopes[currentGun.SCOPE].ReturnPart(), ScopeObj.transform.position, Quaternion.identity);
            if (currentGun.GUNTYPE == WeaponType.pistol)
            {
                if (currentGun.SCOPE >= 2)
                {
                    currentGunComponent.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
                }
                else
                {
                    currentGunComponent.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
                }
            }

            currentGunComponent.transform.parent   = ScopeObj.transform;
            currentGunComponent.transform.position = ScopeObj.transform.position;
            Vector3 pos       = currentGunComponent.transform.position;
            Vector3 scopeSize = currentGunComponent.GetComponent <Renderer>().bounds.size;
            pos.y += (scopeSize.y / 2);
            pos.x += (scopeSize.z / 2);
            currentGunComponent.transform.position = pos;
        }

        List <SCR_WeaponComponent> underBarrels = typesOfGuns[currentGun.TYPE].underBarrel;

        if (underBarrels.Count > 0)
        {
            if (underBarrels[currentGun.UNDERBARREL].ReturnPart())
            {
                currentGunComponent = Instantiate(underBarrels[currentGun.UNDERBARREL].ReturnPart(), underBarrelObj.transform.position, Quaternion.identity);
                currentGunComponent.transform.parent   = underBarrelObj.transform;
                currentGunComponent.transform.position = underBarrelObj.transform.position;
                Vector3 pos  = currentGunComponent.transform.position;
                Vector3 size = currentGunComponent.transform.GetComponent <Renderer>().bounds.size;
                pos.y -= (size.y / 2);
                currentGunComponent.transform.position = pos;
            }
        }

        for (int i = 0; i < ClipObj.transform.childCount; i++)
        {
            if (i <= currentGun.CLIP)
            {
                ClipObj.transform.GetChild(i).gameObject.SetActive(true);
            }
            else
            {
                ClipObj.transform.GetChild(i).gameObject.SetActive(false);
            }
        }

        List <SCR_WeaponComponent> barrel = typesOfGuns[currentGun.TYPE].barells;

        if (barrel.Count > 0)
        {
            if (barrel[currentGun.BARREL].ReturnPart())
            {
                currentGunComponent = Instantiate(barrel[currentGun.BARREL].ReturnPart(), barrelObj.transform.position, Quaternion.identity);
                currentGunComponent.transform.parent   = barrelObj.transform;
                currentGunComponent.transform.position = barrelObj.transform.position;
                Vector3 pos  = currentGunComponent.transform.position;
                Vector3 size = currentGunComponent.transform.GetComponent <Renderer>().bounds.size;
                pos.x += (size.x / 2);
                Transform barrelEnd       = currentWeaponInterface.ReturnGunEnd();
                Vector3   currentPosition = barrelEnd.transform.position;
                currentPosition.x                     += size.x;
                barrelEnd.transform.position           = currentPosition;
                currentGunComponent.transform.position = pos;
            }
        }

        SCR_Ability ability = null;

        if (currentGun.ABILITYTYPE != LegendaryAbilities.Count)
        {
            ability = LegendaryAbilities[currentGun.ABILITYTYPE];
            ability.SetPlayerParent(mPlayerInteracting);
        }

        currentWeaponInterface.SetGunValues(Gun, mPlayerInteracting, ability);
        SpawnedGun.transform.parent   = mParentObject;
        SpawnedGun.transform.rotation = new Quaternion(0, 0, 0, 0);
        SpawnedGun.transform.position = mParentObject.transform.position;
        mPlayerInteracting.GetComponent <SCR_CharacterInventory>().AddWeapon(Gun, SpawnedGun);

        SCR_UIManager.instance.bWeaponGenerated     = false;
        SCR_UIManager.instance.generatedWeaponClass = null;
        SCR_UIManager.instance.WeaponPickupUI("Player1", false);
        SCR_UIManager.instance.WeaponPickupUI("Player2", false);
        mySource.PlayOneShot(weaponPickupEffect);
    }
Exemplo n.º 3
0
    //use this to spawn the last created gun at a specific vector3 position
    public GameObject SpawnCreatedGun(Vector3 mPosition)
    {
        GunValues currentGun = Gun.ReturnGunValues();

        SpawnedGun = Instantiate(typesOfGuns[currentGun.TYPE].ReturnBody(), spawnPos, Quaternion.identity);
        IWeapon      currentWeaponInterface = (IWeapon)SpawnedGun.GetComponent(typeof(IWeapon));
        GunPositions currentGunPos          = currentWeaponInterface.returnPositions();
        GameObject   ScopeObj       = currentGunPos.scopePosition;
        GameObject   underBarrelObj = currentGunPos.underBarrelPosition;
        GameObject   ClipObj        = currentGunPos.clipPosition;
        GameObject   barrelObj      = currentGunPos.barrelPosition;

        GameObject currentGunComponent;
        List <SCR_WeaponPartsClass> scopes = typesOfGuns[currentGun.TYPE].scopes;

        if (scopes[currentGun.SCOPE].ReturnPart())
        {
            Destroy(ScopeObj.transform.GetChild(0).gameObject);
            currentGunComponent = Instantiate(scopes[currentGun.SCOPE].ReturnPart(), ScopeObj.transform.position, Quaternion.identity);
            if (currentGun.GUNTYPE == WeaponType.pistol)
            {
                if (currentGun.SCOPE >= 2)
                {
                    currentGunComponent.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
                }
                else
                {
                    currentGunComponent.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
                }
            }
            currentGunComponent.transform.parent   = ScopeObj.transform;
            currentGunComponent.transform.position = ScopeObj.transform.position;
            Vector3 pos       = currentGunComponent.transform.position;
            Vector3 scopeSize = currentGunComponent.GetComponent <Renderer>().bounds.size;
            pos.y += (scopeSize.y / 2);
            pos.x += (scopeSize.z / 2);
            currentGunComponent.transform.position = pos;
        }


        List <SCR_WeaponComponent> underBarrels = typesOfGuns[currentGun.TYPE].underBarrel;

        if (underBarrels.Count > 0)
        {
            if (underBarrels[currentGun.UNDERBARREL].ReturnPart())
            {
                currentGunComponent = Instantiate(underBarrels[currentGun.UNDERBARREL].ReturnPart(), underBarrelObj.transform.position, Quaternion.identity);
                currentGunComponent.transform.parent   = underBarrelObj.transform;
                currentGunComponent.transform.position = underBarrelObj.transform.position;
                Vector3 pos  = currentGunComponent.transform.position;
                Vector3 size = currentGunComponent.transform.GetComponent <Renderer>().bounds.size;
                pos.y -= (size.y / 2);
                currentGunComponent.transform.position = pos;
            }
        }



        for (int i = 0; i < ClipObj.transform.childCount; i++)
        {
            if (i <= currentGun.CLIP)
            {
                ClipObj.transform.GetChild(i).gameObject.SetActive(true);
            }
            else
            {
                ClipObj.transform.GetChild(i).gameObject.SetActive(false);
            }
        }


        List <SCR_WeaponComponent> barrel = typesOfGuns[currentGun.TYPE].barells;

        if (barrel.Count > 0)
        {
            if (barrel[currentGun.BARREL].ReturnPart())
            {
                currentGunComponent = Instantiate(barrel[currentGun.BARREL].ReturnPart(), barrelObj.transform.position, Quaternion.identity);
                currentGunComponent.transform.parent   = barrelObj.transform;
                currentGunComponent.transform.position = barrelObj.transform.position;
                Vector3 pos  = currentGunComponent.transform.position;
                Vector3 size = currentGunComponent.transform.GetComponent <Renderer>().bounds.size;
                pos.x += (size.z / 2);
                currentGunComponent.transform.position = pos;
                Transform barrelEnd       = currentWeaponInterface.ReturnGunEnd();
                Vector3   currentPosition = barrelEnd.transform.position;
                currentPosition.x                     += size.x;
                barrelEnd.transform.position           = currentPosition;
                currentGunComponent.transform.position = pos;
            }
        }
        SpawnedGun.transform.position = mPosition;

        return(SpawnedGun);
    }