Update: I got it (partially) working! See my second post for how I did it. I am trying to use data from Random.org in a game I am making. While I know that I can use something like Random, I found out that someone made a C# library so fresh data from Random.org can be used instead of the Pseudorandom generator built-in to C#. I tried to add the library in Visual Studio but the game refuses to load when I run it in Unity. The library is available here: http://www.hvass-labs.org/projects/randomops/cs/files/RandomOpsCS2_1.zip FWIW, here are the instructions for the library: 1. Unpack the RandomOps archive to a convenient directory. 2. In MS Visual Studio open the Solution in which you will use RandomOps. 3. Add the RandomOps project to the solution. 4. Add a reference to RandomOps in all the projects which must use it. I'd appreciate any help on getting this to work.
Ah, yes. Sorry I forgot to link to it. It does not have an API but it does have a downloadable file. I've added the link to the OP. Here is what I did to get it working: First, I compiled the DLL in Visual Studio. Next, I added it as a Reference (Project -> Add Reference -> Browse to DLL). NOTE: I also had to move the DLL to the Scripts folder, I'm not sure if there is a way around that. Next, I created a test script (the first one below). Finally, I added a print to my Player script (the second one below) and it prints out the random data successfully. However, if I change what is inside the TrueRandom class it gives an error: "MissingMethodException: Method not found: 'System.Threading.Monitor.Enter'." I'll keep at it and report if/when I figure out a fix. Code (csharp): namespace TrueRNG { public static partial class TrueRandom { public static RandomOps.Ran2 Random = new RandomOps.Ran2(); } } Code (csharp): using UnityEngine; using System.Collections; using TrueRNG; public class Player : MonoBehaviour { private Transform TS; public int pspeed = 20; public static int playerLives = 3; public static int score = 0; float timer = 0f; public GameObject LaserFab; //variable to reference prefab. // Use this for initialization void Start () { TS = transform; TS.position = new Vector3(0, -14.78957f, 0); //Spawn point for (int i = 0; i < 10; i++) { print("True random " + i +" is " + TrueRandom.Random.Uniform()); } } // Update is called once per frame void Update () { TS.Translate(Vector3.right * Input.GetAxis("Horizontal") * pspeed * Time.deltaTime); if (TS.position.x>11.25f || TS.position.x<-11.25f) { TS.position = new Vector3 (TS.position.x*-1, TS.position.y, TS.position.z); } //Fire a laser with the Spacebar. if (Input.GetKeyDown("space")) { //Get pseudo-randomized laser position //This works but is not "truly" random... float laspo = Random.Range(0, 100) > 50 ? -1.917277f : 1.917277f; /* * float laspo = * while (!TrueRandom.Random.IsAvailableUniform()) { print("Waiting for True RNG/Random.org data..."); } */ //Set Laser position Vector3 position = new Vector3(TS.position.x+laspo, TS.position.y+3.50f, TS.position.z); //Fire projectile. Instantiate(Resources.Load("LaserFab"), position, Quaternion.identity); } if (Time.time - timer > 0.4f) { renderer.enabled = true; } print ("Lives remaining: " + playerLives + " Score: " + score + " Current playing time: " + "0"); } void OnTriggerEnter(Collider collider) { if (collider.CompareTag ("Enemy")) { //Tag is name of prefab. //When the enemy hits the player, destroy the player and the enemy. playerLives--; renderer.enabled = false; timer = Time.time; } if (playerLives < 1) Destroy(this.gameObject); } }
whats the problem with this code? it wont stop randomizing the value of a button.. var customGuiStyle : GUIStyle; var mySkin : GUISkin; var mySkin1 : GUISkin; var tex : Texture; function OnGUI() { var w1="abcdef"; var w2="ghijkl"; var top = 50; var ind = 0; var ind1 = new Array(6); var bot=50; for(var x=0;x< w1.length;x++){ //ind1[x]= Random.Range(0,Random.Range(0,5)); ind1[x] = w1[x]; } for (var i = ind1.length - 1; i > 0; i--) { var r = Random.Range(0,i); var temp = ind1; ind1 = ind1[r]; ind1[r] = temp; } for(var z=0;z<=5;z++){ if(GUI.Button(Rect(200 + top,340,40,40),ind1[z].ToString())) { Debug.Log(""); } top+=50; } for(var y=0;y<=5;y++){ var zxc = Random.Range(0,5); if(y>=5){ ind=5; } else{ ind=y; } if(GUI.Button(Rect(200 + bot,390 ,40,40),w2[zxc].ToString())) { Debug.Log("Clicked Button"); } bot+=50; } } }