- Home /
Prevent one from doing action if one is activated (C# UNITY)
Good Day, I just want to ask if how can I do these.
I need to prevent one action from doing something if the another action is activated and vice versa . Here's the code i have written so far.
if (hit == "spr_player")
{
betOnPlayer = true;
if (betOnBanker)
{
Debug.LogError("You already bet on the banker cannot bet on the player"); ;
}
else
{
if (betOnPlayer)
{
bet[0] = chip;
chips_bet[0].enabled = true;
Chips(chip, 0);
Debug.LogError("Betting on the player");
}
else
{
Debug.LogError("You can not bet on the Player");
}
}
}
else if (hit == "spr_banker")
{
if (betOnPlayer)
{
Debug.LogError("You already bet on the banker cannot bet on the player");
betOnBanker = true;
}
else
{
if (betOnBanker)
{
bet[4] = chip;
chips_bet[4].enabled = true;
Chips(chip, 4);
Debug.LogError("Betting on the banker");
}
else
{
Debug.LogError("You can not bet on the Banker");
}
}
}
But the problem here is that I couldn't get to switch it on off . Could someone point out what I am doing wrong.
Comment
Best Answer
Answer by niiicolai · Aug 08, 2018 at 12:26 PM
bool betOnPlayer;
bool betOnBanker;
void Bet (string hit) {
if (hit == "spr_player") {
if (betOnBanker) {
Debug.Log("You already bet on the banker!");
return; // We return the function here to prevent it from running the rest of the code
}
betOnPlayer = true;
BetOnPlayer();
} else if (hit == "spr_banker") {
if (betOnPlayer) {
Debug.Log("You already bet on the player!");
return; // We return the function here to prevent it from running the rest of the code
}
betOnBanker = true;
BetOnBank();
}
}
void BetOnBank() {
// bet on bank behaviour
}
void BetOnPlayer() {
// bet on player behaviour
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
NetworkAnimator: SetBool vs. SetTrigget? 1 Answer
UI button doesn't appear - c# 3 Answers
Bool is still false on another script even if it's its true onTriggerEnter2d 0 Answers
Distribute terrain in zones 3 Answers