Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Value

Discussion in '2D' started by Treqy, Feb 21, 2021.

  1. Treqy

    Treqy

    Joined:
    Aug 31, 2020
    Posts:
    31
    Hello, I am currently working on a "Cookie Clicker" and I have a problem with this project. and I would like, if I buy a "human" one time, that the value in the script increases (every time I buy another person). Here is the script that gives the player the money after a while:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Points : MonoBehaviour
    7. {
    8.     public Text PeopleAmount;
    9.     public Text scoreText;
    10.     public float peopleCounter;
    11.     public float scoreAmount;
    12.     public float pointIncreasedPerSecond;
    13.     public float ShopWithDraw;
    14.  
    15.     void Start()
    16.     {
    17.         scoreAmount = 15f;
    18.         pointIncreasedPerSecond = 0.0f;
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         scoreText.text = "" + (int)scoreAmount;
    24.         scoreAmount += pointIncreasedPerSecond * Time.deltaTime;
    25.  
    26.         if (scoreAmount > PlayerPrefs.GetInt("Highscore"))
    27.         {
    28.             PlayerPrefs.SetInt("Highscore", (int)scoreAmount);
    29.         }
    30.     }
    31.  
    32.     public void WithdrawCurrency()
    33.     {
    34.         if (scoreAmount >= 15)
    35.         {
    36.             Debug.Log("siis0");
    37.             scoreAmount -= 15;
    38.             peopleCounter++;
    39.             PeopleAmount.text = "" + (int)peopleCounter;
    40.         }
    41.     }
    42. }
    43.  
     
  2. Treqy

    Treqy

    Joined:
    Aug 31, 2020
    Posts:
    31
    Couldn't really look for my problem either, because I have no idea what to call it.
     
unityunity