private void loadScene() { SaveData data = SaveSystem.loadPlayer(); if (data.level == SceneManager.GetActiveScene().buildIndex) { Vector3 position = new Vector3(data.playerPosition[0], data.playerPosition[1], data.playerPosition[2]); Player.transform.position = position; HealthAndShield healthAndShield = Player.GetComponent <HealthAndShield>(); healthAndShield.health = data.health; healthAndShield.Shield = data.shield; GunPlaceHolderPlayer gunHolder = player.GetComponentInChildren <GunPlaceHolderPlayer>(); gunHolder.activePrimary = data.primaryGunID; gun Primary = gunHolder.findWeaponByID(data.primaryGunID).GetComponent <gun>(); Primary.ammoInBag = data.PrimaryAmmoInBag; Primary.ammoInMag = data.PrimaryAmmoInMag; gunHolder.activeSecondary = data.secondaryGunID; gun Secondary = gunHolder.findWeaponByID(data.secondaryGunID).GetComponent <gun>(); Secondary.ammoInBag = data.SecondaryAmmoInBag; Secondary.ammoInMag = data.SecondaryAmmoInMag; gunHolder.grenadeCount[0] = data.GrenadeCount[0]; gunHolder.grenadeCount[1] = data.GrenadeCount[1]; gunHolder.grenadeCount[2] = data.GrenadeCount[2]; gunHolder.switchWeapon(); gunHolder.switchWeapon(); } }
public override void interact() { base.interact(); GunPlaceHolderPlayer holder = gameManager.player.GetComponentInChildren <GunPlaceHolderPlayer>(); GameObject c = Instantiate(creator, transform.position, transform.rotation); pupCreater create = c.GetComponent <pupCreater>(); bool replacing; if (holder.activePrimary == id) { replacing = false; } else { replacing = true; ///// gun g = holder.findWeaponByID(holder.activePrimary).GetComponent <gun>(); create.id = g.id; create.ammo = g.ammoInBag + g.ammoInMag; g.ammoInMag = 0; } holder.activePrimary = id; if (holder.holdingPrimary) { holder.switchWeapon(); holder.switchWeapon(); } else { holder.switchWeapon(); } if (replacing) { holder.ActiveGun.GetComponent <gun>().ammoInBag = ammo; create.Create(); } else { holder.ActiveGun.GetComponent <gun>().ammoInBag += ammo; } Destroy(gameObject); }