Search
Get Started
C
C#
•
3y ago
multishep
❔ Random is not working
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,010
Members
View on Discord
Was this page helpful?
Yes
No
M
multishep
OP
•
6/6/23, 5:35 PM
this is a 2d game
M
multishep
OP
•
6/6/23, 5:38 PM
do i need to import anything like in python i
.e
.
, import random
S
Shinigami
•
6/6/23, 5:39 PM
What
's the error it
's showing
?
P
Patrick
•
6/6/23, 5:39 PM
Unity is different from regular
.NET
P
Patrick
•
6/6/23, 5:40 PM
you should be referring to Unity specific randomness
, since
.NET
's doesn
't directly apply here
,
https://docs.unity3d.com/ScriptReference/Random.Range.html
M
multishep
OP
•
6/6/23, 5:40 PM
what
M
multishep
OP
•
6/6/23, 5:40 PM
sorry i have no clue what that means XD what is
.NET
M
multishep
OP
•
6/6/23, 5:41 PM
it says cannot declare a variable of static type
"Random
"
P
Patrick
•
6/6/23, 5:42 PM
Please read the page i linked you
, it has an example as well
.
M
multishep
OP
•
6/6/23, 5:43 PM
So i use random
.range
?
M
multishep
it says cannot declare a variable of static type "Random"
T
Thinker
•
6/6/23, 5:43 PM
Random is a static class
. This means
, among other things
, that you can
't create variables which have the type
Random
Random
, and you can
't do
new Random()
new Random()
.
M
multishep
OP
•
6/6/23, 5:43 PM
i got the code online
M
multishep
So i use random.range?
P
Patrick
•
6/6/23, 5:44 PM
you should use the single instance of
Random
Random
unity has implemented
, yes
P
Patrick
•
6/6/23, 5:44 PM
as per their instructions
M
multishep
OP
•
6/6/23, 5:44 PM
alr thanks ill try change it
M
multishep
i got the code online
T
Thinker
•
6/6/23, 5:44 PM
You likely got the code from somewhere outside the context of Unity
. Unity is very different from
'regular
' C
#
.
A
Accord
•
6/7/23, 5:49 PM
Was this issue resolved
? If so
, run
/close
/close
otherwise I will mark this as stale and this post will be archived until there is new activity
.
Random
Random
Random
Random
new Random()
new Random()
/close
/close