C
C#14mo ago
multishep

❔ Random is not working

13 Replies
multishep
multishep14mo ago
this is a 2d game do i need to import anything like in python i.e., import random
Shinigami
Shinigami14mo ago
What's the error it's showing?
Patrick
Patrick14mo ago
Unity is different from regular .NET
Patrick
Patrick14mo 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
multishep14mo 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
Patrick14mo ago
Please read the page i linked you, it has an example as well.
multishep
multishep14mo ago
So i use random.range?
Thinker
Thinker14mo 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
multishep14mo ago
i got the code online
Patrick
Patrick14mo ago
you should use the single instance of Random unity has implemented, yes as per their instructions
multishep
multishep14mo ago
alr thanks ill try change it
Thinker
Thinker14mo ago
You likely got the code from somewhere outside the context of Unity. Unity is very different from 'regular' C#.
Accord
Accord14mo 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.