Search Unity

Question Generate Random Int without the same in a row

Discussion in 'Visual Scripting' started by wuannetraam, Jan 29, 2023.

  1. wuannetraam

    wuannetraam

    Joined:
    Oct 29, 2019
    Posts:
    87
    I can not get my head around this.

    I have been searching google for a long time to find the answer.
    The answer I found is a c# script


    Code (CSharp):
    1. int randomNumber;
    2. int lastNumber;
    3. int maxAttempts = 10;
    4. void NewRandomNumber()
    5. {
    6.     for(int i=0; randomNumber == lastNumber && i < maxAttempts; i++)
    7.     {
    8.         randomNumber = Random.Range(0, 10);
    9.     }
    10.     lastNumber = randomNumber;
    11. }
    Now I want to recreate this in Visual Scripting but I think I am not doing it the correct way. This is what I got so far.

    What am I doing wrong?
     

    Attached Files:

    • vs.png
      vs.png
      File size:
      384.6 KB
      Views:
      82