- Home /
Any Ideas on how to solve this?
I am relatively new to coding and unity and I was following a guys tutorials on how to make a clicker style game. His code on one of his videos were very buggy and it would always go into the negative if you bought an auto seller, which is an update in the game. I fixed all of bugs that would put you in negative but I am stuck trying to find out a way to solve another bug. What I am currently using is an IEnumerator function with if statements inside. The bug that I am facing is when you hire sellers that sell the ore and they are trying to sell an amount that is bigger than is being made. What happens is it takes away the ore, but it does not credit you for only selling partial of what the miners sell every second. I am trying to find a way that it can sell the amount of ores that is < than the number of sellers. I tried doing an if and else statement inside of another else statement but it freezes all of my code that is inside of the IEnumerator and I am confused on how to fix this. Anyone have an idea on how to fix this issue?
Answer by unity_0sdsWZad6Fwp-A · Nov 20, 2018 at 02:24 AM
@Cornelis-de-Jager here: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AutoSell : MonoBehaviour {
public bool SellingOre = true;
public static int CashIncrease = 1;
public int InternalIncrease;
void Update()
{
CashIncrease = GlobalShop.shopPerSec;
InternalIncrease = CashIncrease;
if (SellingOre == false)
{
SellingOre = true;
StartCoroutine(SellTheOre());
}
}
IEnumerator SellTheOre()
{
if (GlobalOres.OreCount < InternalIncrease)
{
SellingOre = false;
GlobalOres.OreCount = GlobalShop.shopPerSec;
if (GlobalOres.OreCount < 1) ;
{
SellingOre = true;
}
}
else
GlobalCash.CashCount += InternalIncrease;
GlobalOres.OreCount -= GlobalShop.shopPerSec;
yield return new WaitForSeconds(1);
SellingOre = false;
}
}
Your answer
Follow this Question
Related Questions
Circular motion via the mathematical circle equation? 4 Answers
RigidBody 2D x velocity function 1 Answer
if statement for 6 ints help C# 2 Answers
Making slider match health when values are different. 0 Answers
If statement always true 3 Answers