Generating Random Values in Unity

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024
  • Random numbers are pretty useful in any game you can think of, and can be used as a tool to add interesting behavior to your game.
    There are key things to know with generating Random values, how different types work, what utility the Random class provides, and how to seed your random numbers to get predictable results.
    ✨Want to support the channel?
    Buy me a coffee ☕: ko-fi.com/bmoli
    COMMENT if you have any questions or use random numbers in an interesting way!
    SUBSCRIBE for all the follow up videos and to become rich and famous and beautiful
    ➤LIKE the video if you enjoyed, it really helps the channel!
    ➤Join our DISCORD SERVER to become a god amongst men: / discord
    Thanks for watching!
    #bmo #unity #tutorial #random

Комментарии • 17

  • @Camicus27Alt
    @Camicus27Alt Год назад +3

    Even though I already knew a lot about Random and use it in my own games frequently, I've still been too lazy to actually read the documentation and learn more about Unity's version of Random. This answered the few obscure questions I had about the class. Nice video!

  • @vapoman4034
    @vapoman4034 Год назад +2

    Very useful, thanks ! (even the final random, i already subscribe ^^)

  • @revmatch6r
    @revmatch6r Год назад +1

    BABE WAKE UP, NEW BMO JUST DROPPED

  • @emanueltejadacoste2250
    @emanueltejadacoste2250 Год назад

    This channel should be boosted to the moon since its content is a treasure, Amazing ! keep going !

  • @Arcane.after.hours-
    @Arcane.after.hours- Год назад

    this channel is my first destination when i need a tutorial

  • @mandamoon9149
    @mandamoon9149 Год назад +4

    Randomly came to comment how much this random video gave value to my life. Thx BMo

  • @RandomDude00001
    @RandomDude00001 4 месяца назад

    how bout random setactive?

  • @tPlayerioT
    @tPlayerioT Год назад

    i would love to see how to make a random range not repeat. need it for my random spawning objects, if i simple use a random range they might spawn more than twice in the same place (i have specific positions)

    • @BMoDev
      @BMoDev  Год назад +1

      after you roll and select a position you could add that to a list of previouslyRolled values... once you roll another Random.Range check if it exists in previouslyRolled, if not Instantiate and add to previouslyRolled, if it exists then roll again and recheck

    • @tPlayerioT
      @tPlayerioT Год назад

      @@BMoDev oh my god i got it!!! im impressed with myself that i actually managed to do it and thanks for giving me some idea how to do it! (im a beginner so please if the code is terrible it works)
      here is the code if anyone wants then to select the items you just do a for loop and the i being in the list[i].
      i recommend not fully copying but to comprehend
      int iteration = 0;
      for(int i = 0; i < maxItemSpawnPoints; i++)
      {
      randomIndex = Random.Range(0, itemSpawnPoints.Length);
      while(listIndexes.Contains(randomIndex))
      {
      randomIndex = Random.Range(0, itemSpawnPoints.Length);
      if (iteration > itemSpawnPoints.Length)
      {
      Debug.Log("Break While loop");
      break;
      }
      iteration++;
      Debug.Log(iteration + " Iteration number");
      }
      if(!listIndexes.Contains(randomIndex))
      {
      listIndexes.Add(randomIndex);
      Debug.Log("Value added to listindexes");
      }
      }

  • @personalgamedevyt9830
    @personalgamedevyt9830 Год назад +3

    Thank you for the tutorial. I was afraid that this would just be another video on how we could generate random values in general, but I like seeing the methods C#/Unity provides for more specific scenarios!

  • @eileeng2492
    @eileeng2492 Год назад +2

    Hey BMo great video

  • @T3QN1Q
    @T3QN1Q Год назад +1

    wow, you are a good man!

  • @libberator5891
    @libberator5891 Год назад +3

    oMg ThIs wAS SOooOO RaNdoM! xD

  • @zoko41
    @zoko41 Год назад

    HOLYY SHIITTT I LOVE YOU I'VE BEEN SEARCHING AROUND THE INTERNET FOR 5 HOURS AND THEN NOW IT'S OVER FINALLY I LOVE YOU MAAN