Quantcast
Channel: Questions in topic: "upgrade"
Viewing all articles
Browse latest Browse all 371

How to Trigger a Percent Chance Event for an Idle Game?

$
0
0
Hey! I'm making an idle game and there are upgrades that for each click, there is a percent chance of getting a certain extra number of currency. The problem i'm dealing with is that only one upgrade can be referenced, instead of every single one. Can someone help me? Thanks! Here is my code so far: using UnityEngine; using System.Collections; public class CreativityItem : MonoBehaviour { public ClickScript cs; private float baseCost; public float cost; public UnityEngine.UI.Text info; public int count = 0; public float chance; public int clickPwr; public string itemName; // Use this for initialization void Start () { baseCost = cost; } // Update is called once per frame void Update () { info.text = itemName + "\nCost: " + cost + "\nChance: " + (int)chance + "% / 100%"; } public void Upgraded() { if(cost >= cs.likes && count < 20) { cs.likes -= cost; chance += 5f; cost = Mathf.Round(baseCost * Mathf.Pow(1.15f, count)); } } } and also my ClickScript: using UnityEngine; using System.Collections; public class ClickScript : MonoBehaviour { public UnityEngine.UI.Text lpcDisplay; public UnityEngine.UI.Text likeDisplay; public float likes = 0f; public int lpc = 1; public CreativityManager cm; void Update() { likeDisplay.text = "Likes: " + likes; lpcDisplay.text = "Likes per Comment: " + lpc; } public void Clicked() { if(Random.Range(0f, 100f) <= cm.chance) { likes+=(lpc + cm.clickPwr); } else { likes += lpc; } } } I just want to know how to parent a Creativity Manager to my upgrade buttons, so that every lucky click adds x amount of likes to the total (combined with every bonus) for each button. Thanks!

Viewing all articles
Browse latest Browse all 371

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>