Lines 80, 81 and 88 have no effect and do not change the variables as intended. I am able to change the variables on the if statement on line 104 and do not understand why I cannot on the other lines. The if statements definitely are called as it displays the debug.log notifications but the variables do not change.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SlotMachine : MonoBehaviour
{
public bool isSpinning;
public bool slotHandlePressed;
public bool increaseBetPressed;
public int rowOneNum;
public int rowTwoNum;
public int rowThreeNum;
Text rowOneText;
Text rowTwoText;
Text rowThreeText;
Text creditText;
Text betAmountText;
int creditAmount = 1000;
int betAmount;
void Start()
{
creditText = GameObject.Find("Credit").GetComponent<UnityEngine.UI.Text>();
betAmountText = GameObject.Find("BetAmount").GetComponent<UnityEngine.UI.Text>();
rowOneText = GameObject.Find("Row1").GetComponent<UnityEngine.UI.Text>();
rowTwoText = GameObject.Find("Row2").GetComponent<UnityEngine.UI.Text>();
rowThreeText = GameObject.Find("Row3").GetComponent<UnityEngine.UI.Text>();
}
void Update()
{
if (isSpinning == true)
{
rowOneText.text = Random.Range(1, 9).ToString();
rowTwoText.text = Random.Range(1, 9).ToString();
rowThreeText.text = Random.Range(1, 9).ToString();
isSpinning = false;
CheckForWin();
Debug.Log("GIVEN RANDOM NUMBER");
}
if (Input.GetKeyDown("space"))
{
Debug.Log("Credit = " + creditAmount);
Debug.Log("Bet = " + betAmount);
}
}
void CheckForWin()
{
Debug.Log("CHECKED NUMBERS");
int.TryParse(rowOneText.text, out rowOneNum);
int.TryParse(rowTwoText.text, out rowTwoNum);
int.TryParse(rowThreeText.text, out rowThreeNum);
if (rowOneNum == rowTwoNum || rowTwoNum == rowThreeNum || rowOneNum == rowThreeNum)
{
creditAmount = betAmount * 2 + creditAmount;
betAmount = 0;
Debug.Log("WON BET");
}
else
{
betAmount = 0;
Debug.Log("LOST BET");
}
}
void OnMouseDown()
{
if (slotHandlePressed && isSpinning == false)
{
isSpinning = true;
Debug.Log("CLICKED HANDLE");
}
else if (increaseBetPressed && isSpinning == false && creditAmount > 0)
{
creditAmount = creditAmount - 10;
betAmount = betAmount + 10;
Debug.Log("INCREASED BET");
}
}