void Update() { PlayerPrefs.SetString("USER_ID", userId.text); Debug.Log("EatOn"); Debug.Log("Play Start"); }
// Update is called once per frame void Update() { gameObject.GetComponent<Text>().text = "Vidas: " + PlayerPrefs.GetInt("Vidas", 0); }
public void OnTriggerEnter2D(Collider2D collision) { // Ending the game when player touches obstacle. Possible only if shield and boost powerups are disabled. if (collision.gameObject.CompareTag("Player") && playerPow.isProtected == false && playerCon.isBoosted == false && isBroken == false && playerCon.isShooted == false) { audioSource.PlayOneShot(clip); Destroy(particles); playerCon.isShooted = true; mainCam.isShaking = true; sprite.enabled = false; playerCon.animator.enabled = false; bc.enabled = false; player.transform.position = new Vector2(player.transform.position.x - 2, player.transform.position.y); // moving player left a little bit,to avoid second collision,just in case collision would not work. Instantiate(particlehit, gameObject.transform.position, Quaternion.identity); if (gM.deathsCounter == 0) // this happens if player dies for the first time. Player have an ability to revive himself. { if (playerCon.distance > PlayerPrefs.GetFloat("Highscore") - 301 && playerCon.distance < PlayerPrefs.GetFloat("Highscore")) { gM.endScore.text = " Only " + (PlayerPrefs.GetFloat("Highscore") - playerCon.distance) + "m left to a new Highscore! "; gM.endScore.gameObject.SetActive(true); } else { gM.endScore.text = "Keep it up !"; gM.endScore.gameObject.SetActive(true); } gM.totalCoins = PlayerPrefs.GetInt("TotalCoins", 0); gM.reviveText.text = " Revive \n300"; gM.lastLive = true; StartCoroutine("reviveQuestion"); } else if (gM.deathsCounter == 1) // after player dies second time, this happens. { gM.deathsCounter++; playerCon.speed /= 10; gM.restartButton.gameObject.SetActive(true); gM.blackScreen.gameObject.SetActive(true); gM.endScore.gameObject.SetActive(true); gM.coinImage.gameObject.SetActive(false); gM.scoreText.gameObject.SetActive(false); gM.coinsText.gameObject.SetActive(false); gM.pauseButton.gameObject.SetActive(false); if (playerCon.distance < PlayerPrefs.GetFloat("Highscore")) { gM.endScore.text = "You rode " + playerCon.distance + "m!"; } else if (playerCon.distance > PlayerPrefs.GetFloat("Highscore")) { gM.endScore.text = "New Highscore! " + playerCon.distance; } playerCon.isAlive = false; playerCon.enabled = false; playerCon.particleSparks.enableEmission = false; playerCon.rb.gravityScale = 1; } } //this happens if player with turbo collides with obstacle else if (collision.gameObject.CompareTag("Player") && playerPow.isProtected == false && playerCon.isBoosted == true && isBroken == false) { sprite.enabled = false; bc.enabled = false; audioSource.PlayOneShot(clip); Instantiate(smallHit, gameObject.transform.position, Quaternion.identity); Destroy(particles); Destroy(gameObject, 2f); } // if shield powerup enabled and player touches obstacle, shield disapears. Only possible if player does not have boost power up. else if ((collision.gameObject.CompareTag("Player") && playerPow.isProtected == true && playerCon.isBoosted == false && isBroken == false)) { mainCam.isShaking = true; bc.enabled = false; playerPow.isProtected = false; sprite.enabled = false; audioSource.PlayOneShot(shieldDestroy); Instantiate(breakingShield, gameObject.transform.position, Quaternion.identity); Instantiate(smallHit, gameObject.transform.position, Quaternion.identity); Destroy(gameObject, 2f); } // this happens after player collides with broken particle,during wall event. if (collision.gameObject.CompareTag("Player") && isBroken == true) { mainCam.isShaking = true; sprite.enabled = false; Instantiate(brokenParticle, gameObject.transform.position, Quaternion.identity); audioSource.PlayOneShot(clip, 0.5f); Destroy(gameObject, 3); } // if obstacle collides with an exclamation point, obstacle it destroyed. It has to be done, to make visibility on the line with an exclamation. { if (collision.gameObject.tag == ("rocket") && isSingle == true) { Destroy(gameObject); } } }
IEnumerator reviveQuestion() // after player dies,he has option to revive himself. Depending on the will of the player,game can continue,or end. { gM.deathsCounter++; playerCon.speed /= 10; canDestroy = true; playerCon.isAlive = false; playerCon.enabled = false; playerCon.particleSparks.enableEmission = false; gM.skipButton.gameObject.SetActive(true); gM.blackScreen.gameObject.SetActive(true); gM.timer.gameObject.SetActive(true); gM.reviveButton.gameObject.SetActive(true); gM.reviveCoin.gameObject.SetActive(true); gM.pauseButton.gameObject.SetActive(false); yield return(new WaitForSeconds(4)); if (gM.isRevived == true) // if player revived himself { playerCon.particleSparks.enableEmission = true; playerCon.isAlive = true; playerCon.enabled = true; playerCon.bc.enabled = true; playerCon.animator.enabled = true; gM.isRevived = false; playerCon.isShooted = false; gM.reviveTime = 3; playerCon.speed *= 10; gM.pauseButton.gameObject.SetActive(true); gM.restartButton.gameObject.SetActive(false); gM.timer.gameObject.SetActive(false); gM.endScore.gameObject.SetActive(false); gM.blackScreen.gameObject.SetActive(false); gM.reviveButton.gameObject.SetActive(false); gM.reviveCoin.gameObject.SetActive(false); gM.skipButton.gameObject.SetActive(false); spawner.isSpawning = true; audioSource.PlayOneShot(revive, 0.6f); } else // if player didnt use revive button { if (playerCon.distance < PlayerPrefs.GetFloat("Highscore")) { gM.endScore.text = "You rode: " + playerCon.distance + "m!"; } else if (playerCon.distance > PlayerPrefs.GetFloat("Highscore")) { gM.endScore.text = "New Highscore! :" + playerCon.distance; } playerCon.rb.gravityScale = 1; gM.lastLive = true; gM.restartButton.gameObject.SetActive(true); gM.endScore.gameObject.SetActive(true); gM.scoreText.gameObject.SetActive(false); gM.coinImage.gameObject.SetActive(false); gM.coinsText.gameObject.SetActive(false); gM.reviveButton.gameObject.SetActive(false); gM.pauseButton.gameObject.SetActive(false); audioSource.PlayOneShot(death, 0.5f); } }
void LoadData() { oldPlayer = GameObject.FindWithTag("Player"); if (oldPlayer) { Destroy(gameObject); } else { lastPosition.x = PlayerPrefs.GetFloat("PlayerX"); lastPosition.y = PlayerPrefs.GetFloat("PlayerY"); lastPosition.z = PlayerPrefs.GetFloat("PlayerZ"); GameObject respawn = Instantiate(player, lastPosition, transform.rotation) as GameObject; respawn.GetComponent <StatusC>().level = PlayerPrefs.GetInt("PlayerLevel"); respawn.GetComponent <StatusC>().atk = PlayerPrefs.GetInt("PlayerATK"); respawn.GetComponent <StatusC>().def = PlayerPrefs.GetInt("PlayerDEF"); respawn.GetComponent <StatusC>().matk = PlayerPrefs.GetInt("PlayerMATK"); respawn.GetComponent <StatusC>().mdef = PlayerPrefs.GetInt("PlayerMDEF"); respawn.GetComponent <StatusC>().mdef = PlayerPrefs.GetInt("PlayerMDEF"); respawn.GetComponent <StatusC>().exp = PlayerPrefs.GetInt("PlayerEXP"); respawn.GetComponent <StatusC>().maxExp = PlayerPrefs.GetInt("PlayerMaxEXP"); respawn.GetComponent <StatusC>().maxHealth = PlayerPrefs.GetInt("PlayerMaxHP"); //respawn.GetComponent<StatusC>().health = PlayerPrefs.GetInt("PlayerHP"); respawn.GetComponent <StatusC>().health = PlayerPrefs.GetInt("PlayerMaxHP"); respawn.GetComponent <StatusC>().maxMana = PlayerPrefs.GetInt("PlayerMaxMP"); respawn.GetComponent <StatusC>().mana = PlayerPrefs.GetInt("PlayerMaxMP"); respawn.GetComponent <StatusC>().statusPoint = PlayerPrefs.GetInt("PlayerSTP"); mainCam = GameObject.FindWithTag("MainCamera").transform; mainCam.GetComponent <ARPGcameraC>().target = respawn.transform; //------------------------------- respawn.GetComponent <InventoryC>().cash = PlayerPrefs.GetInt("Cash"); int itemSize = player.GetComponent <InventoryC>().itemSlot.Length; int a = 0; if (itemSize > 0) { while (a < itemSize) { respawn.GetComponent <InventoryC>().itemSlot[a] = PlayerPrefs.GetInt("Item" + a.ToString()); respawn.GetComponent <InventoryC>().itemQuantity[a] = PlayerPrefs.GetInt("ItemQty" + a.ToString()); //------- a++; } } int equipSize = player.GetComponent <InventoryC>().equipment.Length; a = 0; if (equipSize > 0) { while (a < equipSize) { respawn.GetComponent <InventoryC>().equipment[a] = PlayerPrefs.GetInt("Equipm" + a.ToString()); a++; } } respawn.GetComponent <InventoryC>().weaponEquip = 0; respawn.GetComponent <InventoryC>().armorEquip = PlayerPrefs.GetInt("ArmoEquip"); if (PlayerPrefs.GetInt("WeaEquip") == 0) { respawn.GetComponent <InventoryC>().RemoveWeaponMesh(); } else { respawn.GetComponent <InventoryC>().EquipItem(PlayerPrefs.GetInt("WeaEquip"), respawn.GetComponent <InventoryC>().equipment.Length + 5); } //---------------------------------- Screen.lockCursor = true; //--------------Set Target to Monster--------------- GameObject[] mon; mon = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject mo in mon) { if (mo) { mo.GetComponent <AIsetC>().followTarget = respawn.transform; } } //---------------Set Target to Minimap-------------- GameObject minimap = GameObject.FindWithTag("Minimap"); if (minimap) { GameObject mapcam = minimap.GetComponent <MinimapOnOffC>().minimapCam; mapcam.GetComponent <MinimapCameraC>().target = respawn.transform; } //Load Quest respawn.GetComponent <QuestStatC>().questProgress = new int[PlayerPrefs.GetInt("QuestSize")]; int questSize = respawn.GetComponent <QuestStatC>().questProgress.Length; a = 0; if (questSize > 0) { while (a < questSize) { respawn.GetComponent <QuestStatC>().questProgress[a] = PlayerPrefs.GetInt("Questp" + a.ToString()); a++; } } respawn.GetComponent <QuestStatC>().questSlot = new int[PlayerPrefs.GetInt("QuestSlotSize")]; int questSlotSize = respawn.GetComponent <QuestStatC>().questSlot.Length; a = 0; if (questSlotSize > 0) { while (a < questSlotSize) { respawn.GetComponent <QuestStatC>().questSlot[a] = PlayerPrefs.GetInt("Questslot" + a.ToString()); a++; } } //Load Skill Slot a = 0; while (a <= 2) { respawn.GetComponent <SkillWindowC>().skill[a] = PlayerPrefs.GetInt("Skill" + a.ToString()); a++; } respawn.GetComponent <SkillWindowC>().AssignAllSkill(); Destroy(gameObject); } }
public static void SaveGame(this Save save, string path) { var data = JsonUtility.ToJson(save); PlayerPrefs.SetString(path, data); }
public void GetHealthVal() { health = PlayerPrefs.GetInt("Health", 3); }
public void SaveHealth() { PlayerPrefs.SetInt("Health", health); }
void Start() { //PlayerPrefs.SetInt("leveldone",40); pannelname = gameObject.name; pannel = string.Concat(pannelname[5], pannelname[6]); pannelint = int.Parse(pannel); //levelcheck = (PlayerPrefs.GetInt("leveldone") + 1); levelcheck = AudioManager.instance.leveldone + 1; if(levelcheck / 8 >= pannelint) { for(int i=0; i< 8; i++) { string star; star =(((pannelint - 1) * 8) + i+1).ToString("0"); // Debug.Log(PlayerPrefs.GetInt(star)); this.transform.GetChild(i).gameObject.GetComponent<Button>().interactable = true; this.transform.GetChild(i).gameObject.transform.GetChild(0).gameObject.SetActive(true); //Debug.Log(levelbutton[i].name); if(PlayerPrefs.GetInt(star) == 3) { this.transform.GetChild(i).gameObject.transform.GetChild(1).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(4).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(5).gameObject.SetActive(true); } if(PlayerPrefs.GetInt(star) == 2) { this.transform.GetChild(i).gameObject.transform.GetChild(2).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(3).gameObject.SetActive(true); } if(PlayerPrefs.GetInt(star) == 1) { this.transform.GetChild(i).gameObject.transform.GetChild(1).gameObject.SetActive(true); } } } else if( levelcheck > 8 * (pannelint -1) && levelcheck < 8 * pannelint ) { level = levelcheck % 8; if (level == 0) level = 8; //GameObject.Find("1 (9)").GetComponent<Button>().interactable = true; //PlayerPrefs.SetInt("1",3); //PlayerPrefs.SetInt("2",2); //PlayerPrefs.SetInt("3",3); //Debug.Log("1 " + PlayerPrefs.GetInt("1")); //Debug.Log("2 " + PlayerPrefs.GetInt("2")); //sDebug.Log("3 " + PlayerPrefs.GetInt("3")); //Debug.Log(level ); //levelbutton[0].GetComponent<Button>().interactable = true; for(int i=0; i< level; i++) { string star; star =(((pannelint - 1) * 8) + i+1).ToString("0"); // Debug.Log(PlayerPrefs.GetInt(star)); this.transform.GetChild(i).gameObject.GetComponent<Button>().interactable = true; this.transform.GetChild(i).gameObject.transform.GetChild(0).gameObject.SetActive(true); //Debug.Log(levelbutton[i].name); if(PlayerPrefs.GetInt(star) == 3) { this.transform.GetChild(i).gameObject.transform.GetChild(1).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(4).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(5).gameObject.SetActive(true); } if(PlayerPrefs.GetInt(star) == 2) { this.transform.GetChild(i).gameObject.transform.GetChild(2).gameObject.SetActive(true); this.transform.GetChild(i).gameObject.transform.GetChild(3).gameObject.SetActive(true); } if(PlayerPrefs.GetInt(star) == 1) { this.transform.GetChild(i).gameObject.transform.GetChild(1).gameObject.SetActive(true); } } } }