Sorry the question doesn’t provide more detail its a little hard to explain
Basically I have a loop being called under a specific circumstance in void Update however when I add an integer in a seperate coroutine (that I call with the loop) it seems to constantly add numbers, it adds about 7 to 14 onto the variable and stops and does it again next time its called
public class InventoryExp : MonoBehaviour
{
public Block.BlockType hitBlockType;
private Block.BlockType lastBlockHit;
public Block.BlockType[] BlockArray;
private int blockHealth;
public GameObject[] Slot;
public Sprite Alpha;
public Image[] SlotImage;
public Sprite[] BlockSprites;
public int[] BlockAmount;
public bool[] BlockInInventory;
private int ID;
private int SlotID;
private Text BlockAmountText;
// Use this for initialization
void Start ()
{
hitBlockType = Block.BlockType.AIR;
ID = 0;
blockHealth = 2;
}
IEnumerator MakeSlot()
{
yield return new WaitForSeconds(0.1f);
SlotImage[SlotID].sprite = BlockSprites[ID];
BlockAmount[ID] = 1;
BlockAmountText = Slot[ID].GetComponentInChildren<Text>();
BlockAmountText.text = BlockAmount[ID].ToString();
BlockInInventory[ID] = true;
yield return new WaitForSeconds(0.1f);
}
IEnumerator AddToSlot()
{
yield return new WaitForSeconds(0.1f);
BlockAmount[ID] += 1;
BlockAmountText = Slot[ID].GetComponentInChildren<Text>();
BlockAmountText.text = BlockAmount[ID].ToString();
yield return new WaitForSeconds(0.1f);
}
public IEnumerator GetBlock()
{
blockHealth = GameObject.Find("Camera").GetComponent<BlockInteraction>().Health;
yield return new WaitForSeconds(0.1f);
hitBlockType = GameObject.Find("Camera").GetComponent<BlockInteraction>().typeOfBlock;
}
// Update is called once per frame
void Update () {
if (hitBlockType != Block.BlockType.AIR)
{
ID = 0;
if (blockHealth == 0)
{
while (ID != BlockArray.Length - 1)
{
if (hitBlockType == BlockArray[ID])
{
SlotImage[SlotID] = Slot[SlotID].gameObject.GetComponent<Image>();
if (BlockInInventory[ID] == true)
{
StartCoroutine(AddToSlot());
return;
}
else if (SlotImage[SlotID].sprite == Alpha)
{
StartCoroutine(MakeSlot());
return;
}
else if (SlotImage[SlotID].sprite != Alpha)
{
SlotID = SlotID + 1;
}
}
else if (hitBlockType != BlockArray[ID])
{
ID = ID + 1;
}
}
}
}
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(GetBlock());
}
}
}
Would appreciate it if anybody could work this out I’ve been scratching my head for hours