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 /
This question was closed Jul 02, 2017 at 04:03 PM by ShadyProductions for the following reason:

duplicate

avatar image
0
Question by Expheria · Jul 01, 2017 at 11:21 PM · script.float

Same float for the same buttons.

I'm making an idle game, for each upgrade button I am using the same floats, not creating another Script file or I'd have millions of them.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class UpgradeEpherumDrillers : MonoBehaviour {
 
     public GatherButton g;
 
     public UnityEngine.UI.Text UpgradeNameText;
     public UnityEngine.UI.Text UpgradeAmountText;
     public UnityEngine.UI.Text UpgradeInfoText;
 
     public UnityEngine.UI.Slider TimerSlider;
     public GameObject SliderToDisable;
 
     [Header("Drill Properties")]
     public string DrillerName = "";
     public float UpgradeCost = 500;
     public float UpgradeEpherumPerSecBy = 0;
     public float LevelNeededToUnlock = 0;
 
     [HideInInspector]
     public float EpherumPerSec = 0;
     [HideInInspector]
     public float UpgradeAmount = 0;
 
     [Space]
 
     [Header("Timer")]
     public float AutoTimerReset = 0;
     public float AutoTimer = 0;
 
     void Start(){
         UpgradeCost = PlayerPrefs.GetFloat ("UpgradeUpgradeCost", UpgradeCost);
         UpgradeEpherumPerSecBy = PlayerPrefs.GetFloat ("UpgradeUpgradeEpherumPerSecBy", UpgradeEpherumPerSecBy);
         LevelNeededToUnlock = PlayerPrefs.GetFloat ("UpgradeLevelNeededToUnlock", LevelNeededToUnlock);
         EpherumPerSec = PlayerPrefs.GetFloat ("UpgradeEpherumPerSec", EpherumPerSec);
         UpgradeAmount = PlayerPrefs.GetFloat ("UpgradeUpgradeAmount", UpgradeAmount);
         AutoTimerReset = PlayerPrefs.GetFloat ("UpgradeAutoTimerReset", AutoTimerReset);
         AutoTimer = PlayerPrefs.GetFloat ("UpgradeAutoTimer", AutoTimer);
     }
 
     void Update () {
         PlayerPrefs.SetFloat ("UpgradeUpgradeCost", UpgradeCost);
         PlayerPrefs.SetFloat ("UpgradeUpgradeEpherumPerSecBy", UpgradeEpherumPerSecBy);
         PlayerPrefs.SetFloat ("UpgradeLevelNeededToUnlock", LevelNeededToUnlock);
         PlayerPrefs.SetFloat ("UpgradeEpherumPerSec", EpherumPerSec);
         PlayerPrefs.SetFloat ("UpgradeUpgradeAmount", UpgradeAmount);
         PlayerPrefs.SetFloat ("UpgradeAutoTimerReset", AutoTimerReset);
         PlayerPrefs.SetFloat ("UpgradeAutoTimer", AutoTimer);
 
         if (LevelNeededToUnlock <= g.CurrentLevel) {
             UpgradeNameText.text = DrillerName;
             UpgradeAmountText.text = "Level " + UpgradeAmount + " " + "Cost " + UpgradeCost;
             UpgradeNameText.rectTransform.offsetMin = new Vector2 (UpgradeNameText.rectTransform.offsetMin.x, UpgradeNameText.rectTransform.offsetMin.x + 40);
             SliderToDisable.SetActive(true);
             UpgradeNameText.color = Color.white;
         } else if (LevelNeededToUnlock >= g.CurrentLevel) {
             UpgradeNameText.text = "Level Required " + LevelNeededToUnlock;
             UpgradeAmountText.text = "";
             UpgradeInfoText.text = "";
             UpgradeNameText.rectTransform.offsetMin = new Vector2 (UpgradeNameText.rectTransform.offsetMin.x, UpgradeNameText.rectTransform.offsetMin.x);
             SliderToDisable.SetActive(false);
         }
 
         if (LevelNeededToUnlock <= g.CurrentLevel) {
             if (UpgradeAmount == 0) {
                 UpgradeInfoText.text = "Not Bought";
             } else if (UpgradeAmount >= 0) {
                 UpgradeInfoText.text = "Epherum Per Second + " + UpgradeEpherumPerSecBy;
             }
         }
 
         if (UpgradeAmount == 0) {
             SliderToDisable.SetActive (false);
             AutoTimer = AutoTimerReset;
         } else if (UpgradeAmount >= 0) {
             SliderToDisable.SetActive (true);
         }
 
 
         TimerSlider.minValue = 0;
         TimerSlider.maxValue = AutoTimerReset;
         TimerSlider.value = AutoTimer;
         AutoTimer -= Time.deltaTime;
         if (UpgradeAmount >= 0) {
             if (AutoTimer <= 0) {
                 g.EpherumAmount += EpherumPerSec;
                 AutoTimer += AutoTimerReset;
             }
         }
     }
 
     public void UpgradeBought(){
         if (g.CurrentLevel >= LevelNeededToUnlock) {
             if (g.EpherumAmount >= UpgradeCost) {
                 UpgradeAmount += 1;
                 g.EpherumAmount -= UpgradeCost;
                 UpgradeCost += Mathf.Lerp (UpgradeCost, UpgradeCost, UpgradeCost);
                 g.EpherumPerSecondAmount += UpgradeEpherumPerSecBy;
                 EpherumPerSec += UpgradeEpherumPerSecBy;
             }
         }
     }
 
 }
 

When I try and save the floats with PlayerPrefs, when I load up the game all the buttons have the same cost, upgrade amount and the same epherumpersec.

How do I make it where they do not save for each button?

Example: I have a IronDrill and a CopperDrill, they both use the same floats and the same everything basically, just different prices and different epherumpersec. but when I save them they all have the same upgrade cost and the same epherumpersec. Thanks for the help :^]

Comment
Add comment
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

108 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

Related Questions

How to set float, bool from one script to the other? 1 Answer

,Attack and chase range issue 2 Answers

How to script float the object for add to state machine 0 Answers

Camera FX to fade out back to normal 0 Answers

2D drag script Need Help! 1 Answer


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