public void SetGunValues(SCR_GunClass mWeaponValues, GameObject mplayerObj, SCR_Ability mWeaponAbility) { _weaponStructure = mWeaponValues; _gunValues = _weaponStructure.ReturnGunValues(); _playerParent = mplayerObj; gunAbility = mWeaponAbility; }
void RpcFindActiveGun(int a) { activeGun = gameObject.transform.GetChild(4).gameObject; values = activeGun.GetComponent <GunValues>(); bulletRefTransform = activeGun.transform.GetChild(1).transform; }
void RpcSetParent(GameObject go) { activeGun.SetActive(false); go.transform.parent = transform; activeGun = go; values = go.GetComponent <GunValues>(); go.transform.gameObject.GetComponent <CapsuleCollider2D>().enabled = false; bulletRefTransform = activeGun.transform.GetChild(1).transform; }
public void AddWeapon(SCR_GunClass newWeapon, GameObject gunBody) { bPlayerHasGun = true; if (_gunInventory[_currentlySelectedWeapon].gunObject) { _gunInventory[_currentlySelectedWeapon].gunObject.SetActive(false); } GunValues currentWeapon = newWeapon.ReturnGunValues(); int weaponSlot = 0; switch (currentWeapon.SLOTTYPE) { case GunTypes.Primary: weaponSlot = 0; break; case GunTypes.Secondary: weaponSlot = 1; break; case GunTypes.Infinite: weaponSlot = 2; break; case GunTypes.Throwable: weaponSlot = 3; break; } _currentWeaponInterface = (IWeapon)gunBody.GetComponent(typeof(IWeapon)); Destroy(_gunInventory[weaponSlot].gunObject); _gunInventory[weaponSlot].gunObject = gunBody; _currentlySelectedWeapon = weaponSlot; int _clipSize = _currentWeaponInterface.ReturnClipSize(); _currentWeaponInterface.setCurrentClip(_clipSize); _attackScript.UpdateWeaponInterface(_currentWeaponInterface); float percentage = _currentWeaponInterface.ReturnClipSize() * playerStats.GetUpgradeLevelMultiplier(PlayerUpgradeType.reload); uiManagerScript.SetGauge(gameObject.tag, (int)percentage); uiManagerScript.SetCurrentAmmoText(gameObject.tag, _currentWeaponInterface.ReturnClipSize(), _gunInventory[weaponSlot].currentAmmo, _currentWeaponInterface.ReturnClipSize()); PlaySwitchingSound(); if (weaponSlot != 3) { uiManagerScript.SwitchGunImages(gameObject.tag, false, ThrowableType.FireGrenade, false, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().GUNTYPE, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().RARITY, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().EFFECT); } if (weaponSlot == 0 || weaponSlot == 1) { uiManagerScript.EnableWeaponSlot(gameObject.tag, _currentlySelectedWeapon); } uiManagerScript.SwitchSelectedWeaponUI(gameObject.tag, _currentlySelectedWeapon); }
public GunValues ReturnGunValues() { GunValues currentValues = new GunValues(); currentValues.ACCURACY = Accuracy; currentValues.DPS = DamagePerShot; currentValues.CLIPSIZE = ClipSize; currentValues.RATEOFFIRE = RateOfFire; currentValues.RARITY = Rarity; currentValues.TYPE = body; currentValues.SCOPE = scope; currentValues.BARREL = barrel; currentValues.UNDERBARREL = underBarrel; currentValues.CLIP = clip; currentValues.SLOTTYPE = WeaponSlot; currentValues.GUNTYPE = typeOfWeapon; currentValues.EFFECT = effect; currentValues.ABILITY = Ability; currentValues.ABILITYTYPE = typeOfAbility; return(currentValues); }
void Awake() { if (!IsInfinitePistol) { _weaponStructure = new SCR_GunClass(); _gunValues = new GunValues(); } _playerParent = null; if (IsInfinitePistol) { _gunValues = _weaponStructure.ReturnGunValues(); _currentClip = _gunValues.CLIPSIZE; } currentGunShotSource = GetComponent <AudioSource>(); currentMuzzle = Instantiate(muzzle, _gunPosition.position, Quaternion.identity); currentMuzzle.transform.parent = _gunPosition.transform; currentMuzzle.transform.localRotation = new Quaternion(0, 0, 0, 0); currentMuzzle.transform.localScale = new Vector3(muzzleFlashScale, muzzleFlashScale, muzzleFlashScale); currentMuzzle.SetActive(false); }
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); }
//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); }
void RpcChangeGun(int childIndex) { switch (childIndex) { case 1: transform.GetChild(4).gameObject.SetActive(true); activeGun = transform.GetChild(4).gameObject; values = activeGun.GetComponent <GunValues>(); bulletRefTransform = activeGun.transform.GetChild(1).transform; if (transform.childCount >= 6) { transform.GetChild(5).gameObject.SetActive(false); } if (transform.childCount >= 7) { transform.GetChild(6).gameObject.SetActive(false); } break; case 2: if (transform.childCount < 6) { return; } transform.GetChild(5).gameObject.SetActive(true); activeGun = transform.GetChild(5).gameObject; values = activeGun.GetComponent <GunValues>(); bulletRefTransform = activeGun.transform.GetChild(1).transform; transform.GetChild(4).gameObject.SetActive(false); if (transform.childCount >= 7) { transform.GetChild(6).gameObject.SetActive(false); } break; case 3: if (transform.childCount < 7) { return; } transform.GetChild(6).gameObject.SetActive(true); activeGun = transform.GetChild(6).gameObject; values = activeGun.GetComponent <GunValues>(); bulletRefTransform = activeGun.transform.GetChild(1).transform; transform.GetChild(4).gameObject.SetActive(false); if (transform.childCount >= 6) { transform.GetChild(5).gameObject.SetActive(false); } break; } }