How to make a script change what it does depending on what an integer equals

So in this example im trying to make it so if the integer = 1 it says something and updates the integer to 5, then when you click on it again it says something different because it equals something different. Heres my script, any help is greatly appreciated`using System.Collections;

using System.Collections.Generic;
using UnityEngine;

public class printscript2 : MonoBehaviour {

int one = 1;

void OnMouseDown()
{
    if (one < 2)
    {
        print("hello");
        int one = 5;
        Debug.Log(one);
    }
    if (one > 4)
    {
        print("welcome to sunnyvale");
    }
}

Hi @Phoenix3666 I am not sure what you want exactly but i will try my best. And i hope this will help.

In one of my project i want to make a reward system in which player will be awarded by watching full ad and the reward type will be the type of player choice so i did it like this.

Step 1:

int playerSelectedAwardType=0; // 0 for no award, 1 for coins and so on…

OnAdFinish()

{

  switch(playerSelectedAwardType)

          case 0:
                  print("this is casual ad...");
          break;
          case 1:
                 print("Awarding player with coins");
          break;
         case 2:
                 print("Awarding player with Potions");
          break;

}

step 2:
now make another function like this:

AwardPlayerWith(int AwardType)

{

       playerSelectedAwardType = AwardType;

}

Step 3: now on button clicke event i just called the function “AwardPlayerWith(value)” with int value.

and the script did what i expected. so i think it might help. in case of any question feel free to ask… :slight_smile:

An alternate way is to use a Random number generator to change the value of “one”.

First: remove the line in your if statement that sets one = 5;

Second: add a line at the bottom of the OnMouseDown method. This new line will change the value of “one” to a different random integer.

    int one = 1;
    int minInteger = 0;
    int maxInteger = 9;     //Random.Range will give you an integer between 0 and 8 (9 is excluded)    

    void OnMouseDown()
    {
        if (one < 2)
        {
            print("hello");            
            Debug.Log(one);
        }
        if (one > 4)
        {
            print("welcome to sunnyvale");
        }

        one = Random.Range(minInteger, maxInteger);
    }