Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by joshuakeedy · May 31, 2019 at 12:44 PM · uitextplayerprefspurchase

PlayerPrefs and Text not working but no errors are given.

Hi, The following scripts are meant to display the amount of WipeOuts left in the game according to how many the player has already used, however it is not working. Unfortunately, I am getting no errors and can't see what the problem is. Many thanks for any help I get as i am kind of a noob to Unity and this is my first game. Many thanks, Josh :)

Text Display Script:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class NumOfWipeOutsCounter : MonoBehaviour
 {
     public int WipeOuts = 0;
     public Text NumOfWipeOutsTextCounter;
 
     void Start ()
     {
         //PlayerPrefs.SetInt("WipeOutsMaster", WipeOuts);
         Debug.Log("TestStart");
     }
 
     // Update is called once per frame
     void Update ()
     {
         //PlayerPrefs.SetInt("WipeOutsBase", WipeOuts);
 
         //int WipeOutsInternal = PlayerPrefs.GetInt("WipeOuts");
 
         //NumOfWipeOutsTextCounter.text = "Wipe Outs :" + WipeOuts.ToString();
 
         int WipeOutsMasterInternal = PlayerPrefs.GetInt("WipeOutsMaster");
 
         NumOfWipeOutsTextCounter.text = "Wipe Outs :" + WipeOutsMasterInternal.ToString();
 
         Debug.Log("WipeOutMasterInternal :" + WipeOutsMasterInternal);
 
         Debug.Log("TestUpdate");
     }
 }
 

Main Wipe Out Controller Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 
 public class WipeOut : MonoBehaviour
 {
     //NumOfWipeOutsCounter WipeOutCounterInternal;
     //public GameObject WipeOutCounterInternal;
     public GameObject WipeOutPrefab;
     //public GameObject WipeOutCounter;
     //public GameObject numOfWipeOutsCounterInternal;
     public GameObject Balloons;
     public GameObject WipeOutCounter;
     GameObject wipeOutCounter;
     //WipeOutCounter wipeOutCounter;
     bool allowWipeOut = false;
     NumOfWipeOutsCounter numOfWipeOutsCounter;
     float destroyTimer = 0.25f;
 
     // Start is called before the first frame update
     void Start()
     {
         WipeOutCounter = GameObject.Find("WipeOutCounter");
         //numOfWipeOutsCounter = WipeOutCounterInternal.GetComponent<NumOfWipeOutsCounter>();
         numOfWipeOutsCounter = WipeOutCounter.GetComponent<NumOfWipeOutsCounter>();
         GameObject WipeOutPrefab = GameObject.Find("Pixel Art Character 1 Export");
         Debug.Log("WipeOutScriptStarted");
     }
 
     // Update is called once per frame
     void Update()
     {
         int WipeOutMasterInternal = PlayerPrefs.GetInt("WipeOutsMaster");
 
         int TestWipeOuts = PlayerPrefs.GetInt("WipeOutsBase");
 
         if (/*numOfWipeOutsCounter.WipeOuts*/WipeOutMasterInternal >= 1)
         {
             allowWipeOut = true;
             Debug.Log("WipeOutStage1");
         }
 
         if (allowWipeOut = true && Input.GetKeyDown("space"))
         {
             Instantiate(WipeOutPrefab);
             //numOfWipeOutsCounter.WipeOuts--;
             WipeOutMasterInternal--;
             Destroy(GameObject.Find("Balloons(Clone)"));
             Destroy(GameObject.Find("PixelArt Character 1 Export(Clone)"), destroyTimer);
             Debug.Log("WipeOutStage2");
         }
         if (/*numOfWipeOutsCounter.WipeOuts*/WipeOutMasterInternal == 0)
         {
             allowWipeOut = false;
             numOfWipeOutsCounter.WipeOuts = 0;
             Debug.Log("WipeOutStage3");
         }
     }
 }
 

Wipe Out Purchase Script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GoldPurchaseScript : MonoBehaviour
 {
     //THIS IS THE WIPE OUT PURCHASE SCRIPT - NOT THE GOLD PURCHASE SCRIPT
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     public void ButtonClick ()
     {
         Debug.Log("Button Clicked");
         //int NumOfWipeOuts = PlayerPrefs.GetInt("WipeOutsBase");
 
         //PlayerPrefs.SetInt("WipeOuts", NumOfWipeOuts + 20);
 
         int BuyWipeOutsCounterInternal = PlayerPrefs.GetInt("WipeOutsMaster");
 
         //PlayerPrefs.SetInt("WipeOutsMaster", PlayerPrefs.GetInt("WipeOutsMaster") + 20);
         PlayerPrefs.SetInt("WipeOutsMaster", BuyWipeOutsCounterInternal + 20);
     }
 }
 

Again thanks, Josh :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joshuakeedy · Jun 01, 2019 at 11:39 AM 0
Share

Please respond :).

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by joshuakeedy · Jun 01, 2019 at 11:51 AM

Fixed this issue - all I had to do was nest the bottom two if statements in the top if statement and that fixed the problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

253 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using PlayerPrefs to store string but it won't update on my UI 1 Answer

saving a text into a player pref 0 Answers

how to display UI text in every scene with same text inside?? 0 Answers

easy UI text question text doesnt update 1 Answer

Help! with the Message text 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges