Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MattDahEpic · May 21, 2014 at 07:53 PM · randomdate

How to make sure a sequence is COMPLETELY random?

I have a maze in which a pressure plate randomly selects a wall from around it, if it exists remove it, if not try again. Once successful, it destroys the pressure plate so it cant be triggered again (if it finds no walls, it infinite loops...)

All I'm trying to do is make sure that the Random I'm using is actually random. Right no I have it using Random.seed = System.Environment.TickCount and I'm relying on the fact that the game is not optimized and is laggy, to wait for the script to initalize in a different number of ticks. Right now, it seems random, but it is only actually 3-4 real paths, that are selected in a random order. I looked in the Random.seed documentation, and it says something about setting it to the system date and time, and I was wondering how to do that (it seems like it'd be more random). When I use the Date() to set the seed, apparently you can't change a function to an int.

Current Code:

 var wall1:GameObject;
 var wall2:GameObject;
 var wall3:GameObject;
 var wall4:GameObject;
 var pressurePad:GameObject;
 public var randomWall:int;
 public var canRun:boolean = true;
 public var platesTriggered:float;
 public var wallsRemoved:float;
 public var clip:AudioClip;
 
 function Start () {
     Random.seed = System.Environment.TickCount;
 }
 
 function OnTriggerEnter (other:Collider) {
     canRun = true;
     platesTriggered = platesTriggered + 1;
     RemoveDoor();
 }
 
 function RemoveDoor() {
     if (canRun == true) {
         randomWall = Random.Range(0,5); //random int between 1-4
         print(randomWall);
         if (wall1 != null && randomWall == 1 && wall1.activeInHierarchy == true) { //wall 1 selected
             wall1.SetActive(false);
             wallsRemoved = wallsRemoved + 1;
             AudioSource.PlayClipAtPoint(clip, wall1.transform.position);
             Destroy(pressurePad);
             canRun = false;
         }
         else if (wall2 != null && randomWall == 2 && wall2.activeInHierarchy == true) { //wall 2 selected
             wall2.SetActive(false);
             wallsRemoved = wallsRemoved + 1;
             AudioSource.PlayClipAtPoint(clip, wall2.transform.position);
             Destroy(pressurePad);
             canRun = false;
         }
         else if (wall3 != null && randomWall == 3 && wall3.activeInHierarchy == true) { //wall 3 selected
             wall3.SetActive(false);
             wallsRemoved = wallsRemoved + 1;
             AudioSource.PlayClipAtPoint(clip, wall3.transform.position);
             Destroy(pressurePad);
             canRun = false;
         }
         else if (wall4 != null && randomWall == 4 && wall4.activeInHierarchy == true) { //wall 4 selected
             wall4.SetActive(false);
             wallsRemoved = wallsRemoved + 1;
             AudioSource.PlayClipAtPoint(clip, wall4.transform.position);
             Destroy(pressurePad);
             canRun = false;
         }
         else {
             RemoveDoor();
         }
     }
 }

I'd be cool if you could help!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rutter · May 21, 2014 at 07:45 PM 1
Share

Unity automatically initializes the seed using the system clock. That's pretty standard practice.

avatar image Eric5h5 · May 21, 2014 at 07:59 PM 1
Share

In other words, leave out the Random.seed part. Only use Random.seed if you want repeatable results.

avatar image MattDahEpic · May 21, 2014 at 08:21 PM 0
Share

That worked!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random.seed Repeating 2 Answers

Create number of enemies when one is deid 1 Answer

¿how to take all values from an array without order? 2 Answers

Using arrays to randomly select an object 0 Answers

Random Range Seems... Unrandom 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges