Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

(solved thank you !)

Discussion in 'Getting Started' started by Sylvir, Mar 31, 2015.

  1. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    so i am working on a clicker incremental game, I have 2 scripts set up, and its working to add on clicks, and even the upgrades work.. but the text for some reason i cant get to appear and count how many you have.

    here are my scripts,

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class UpgradeManager : MonoBehaviour {
    5.  
    6.     public Click click;
    7.     public UnityEngine.UI.Text itemInfo;
    8.     public float cost;
    9.     public int count = 0;
    10.     public int clickPower;
    11.     public string itemName;
    12.     private float _newCost;
    13.  
    14.  
    15.     void update(){
    16.         itemInfo.text = itemName + "\nCost: " + cost + "\nPower: +" + clickPower;
    17.     }
    18.  
    19.     public void PurchasedUpgrade(){
    20.         if (click.virus >= cost) {
    21.             click.virus -= cost;
    22.             count += 1;
    23.             click.virusPerClick += clickPower;
    24.             cost = Mathf.Round(cost * 1.15f);
    25.             _newCost = Mathf.Pow (cost, _newCost = cost);
    26.         }
    27.     }
    28.  
    29. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Click : MonoBehaviour {
    5.  
    6.     public UnityEngine.UI.Text goldDisplay;
    7.     public float virus  = 0.00f;
    8.     public int virusPerClick = 1;
    9.  
    10.  
    11.     void update(){
    12.         goldDisplay.text = "Gold: " + virus;
    13.  
    14.     }
    15.  
    16.     public void Clicked(){
    17.         virus += virusPerClick;
    18.  
    19.     }
    20.  
    21. }
    22.  
    i then drug the text object into the clicker object, but for some reason it still doesnt count. if anyone could help me out that would be great, thanks! or if you have a better suggestion about how to get this done that would be great too, just looking for any kind of thoughts as to why im not getting the text to show and update thanks!
     
  2. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    i was going off a gold miner tutorial, started switchign it over to viruses, but it didnt work before i started changing it over either
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    update should be Update
     
  4. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    ah, doh! i knew that.. thanks for the responce. are you lds? i am as well :p
     
  5. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    i fixed that, and the text still seems to not be updating, it counts when i click and upgrades still. ill look at it some more, is there anything special i need to do with the text object i make to put in the slot for the count? or can i just make a ui object text, and then drag it into that slot ?
     
  6. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    nevermind, i worked it out, thanks! i have to put the game object with the clicking script into the slot, not the script. :)
     
  7. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    hmm, any idea the best way to make a check? im trying to check if you have 50 tech points, then it will subtract 50 tech points, and let you buy a virus. here is my code, trying to work out what im missing again. thanks!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class VirusClick : TPB  {
    5.  
    6.     public int cost = 50;
    7.     public VirusClick click;
    8.   //  public UnityEditor.UnityEngine.UI.text vpc;
    9.     public UnityEngine.UI.Text VirusCount;
    10.     public float virus  = 0.00f;
    11.     public int virusPerClick = 1;
    12.  
    13.     //public int techPoints;
    14.  
    15.     void update(){
    16.         VirusCount.text = "Virus Count: " + virus;
    17.     //    vpc.text = "VPC: " + virusPerClick;
    18.  
    19.     }
    20.  
    21.     public void Clicked(){
    22.         if(techPoints >= cost) {
    23.             techPoints -= cost;
    24.             virus += 1;
    25.  
    26.         }
    27.     }
    28.  
    29. }
    30.