C
C#2y ago
multishep

❔ Random is not working

13 Replies
multishep
multishepOP2y ago
this is a 2d game do i need to import anything like in python i.e., import random
Shinigami
Shinigami2y ago
What's the error it's showing?
Patrick
Patrick2y ago
Unity is different from regular .NET
Patrick
Patrick2y ago
you should be referring to Unity specific randomness, since .NET's doesn't directly apply here, https://docs.unity3d.com/ScriptReference/Random.Range.html
multishep
multishepOP2y ago
what sorry i have no clue what that means XD what is .NET it says cannot declare a variable of static type "Random"
Patrick
Patrick2y ago
Please read the page i linked you, it has an example as well.
multishep
multishepOP2y ago
So i use random.range?
Thinker
Thinker2y ago
Random is a static class. This means, among other things, that you can't create variables which have the type Random, and you can't do new Random().
multishep
multishepOP2y ago
i got the code online
Patrick
Patrick2y ago
you should use the single instance of Random unity has implemented, yes as per their instructions
multishep
multishepOP2y ago
alr thanks ill try change it
Thinker
Thinker2y ago
You likely got the code from somewhere outside the context of Unity. Unity is very different from 'regular' C#.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server