jeudi 27 juillet 2017

Unity - Cannot generate random number within a class construct

I have been trying to create my own class using C# in Unity but I've come across a small issue. Within my PlayerClass construct I want to generate a string of six random numbers using Random.Range (0, 9) use as a reference number. Currently, the line of code I am using to do this, looks like this:

refNum = Random.Range (0, 9) + Random.Range (0, 9) + Random.Range (0, 9) + Random.Range (0, 9) + Random.Range (0, 9) + Random.Range (0, 9);

I have created the variable refNum outside of the construct at the top of the class. Every time I run my game I get an error saying I cannot generate random numbers from within a class construct. Does anybody know a way around this?

Many Thanks,

Tommy




Aucun commentaire:

Enregistrer un commentaire