Search Unity

Question Russian Roulette Loop

Discussion in 'Scripting' started by shemtom2002ke, Sep 25, 2021.

  1. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    25
    Hello Guys, thanks to everyone who has taken their time reading this problem or even viewing it. I currently encountered a problem in which I was seeking help. I was building a Russian roulette type of game but I was trying to use a loop within the code. I have commented on what I wanted to code in my script. Below is a snapshot of the script.

    Code (CSharp):
    1.     private void Start()
    2.     {
    3.         //on start make the bullet position to 1 default and later on update to the random bullet when the game is over
    4.        
    5.     }
    6.     private void RandomBullet()
    7.     {
    8.         //if the game is over random generate the bullet position (use a bool to detect)
    9.         //if the game starts random generate the bullet position (on click restart/ use a bool)
    10.        
    11.     }
     
  2. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    25
    the loop should be able to start from 1 to 6 and can also restart again when game is over or when restating the game
     
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I cant seem to find a question.

    You want to do something russion roulette related. Great.
    You encountered a problem. Alright, what problem?
    You want to use a loop.. ok.. what for, what is your problem?
    You wrote comments into your code. Alright, but what is the question?
     
    shemtom2002ke likes this.
  4. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    25
    How do you make a loop which can restart? what I mean is for example when the bullet on start is at 1 so when the game is over the bullet position to be randomly changed to another position using a random.range(1,6) or increment by 1...but the loop should only range from 1 to 6 and can also restart again to 1 or within the range of 1 to 6 and not get past 6.
    The problem which I had was getting my bullet position to randomly position at every start of the game or when the game is over...I have the idea but I don't know the way forward and how to implement it.
    I don't know if this helps!
     
  5. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I wouldnt use a loop at all.
    Generate some number 0-5. When the user pulls the trigger, if the number is 0 he dies. Decrement the number.
    Repeat until .. the user dies?

    Rinse and repeat, as in generate a new number and that's it pretty much.
    The rest is animations and user input. Unless im misunderstanding what you are actually trying to achieve.

    Do you need anything more than that?
     
    shemtom2002ke likes this.
  6. shemtom2002ke

    shemtom2002ke

    Joined:
    Jul 5, 2021
    Posts:
    25
    it worked thank you so much...
     
    Yoreki likes this.