Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Logystone

need help with Random array set-activating objects and deactivating

Question

Hello everyone

this is "ShapeChangeBeta" Script, i want to activate a one GameObject in an array  and disable the rest and it works but sometimes when i click the button it activate a GameObject 2-3 times in row means repeating(EXAMPLE : like the cube is active and when i click the button to activate another shape like circle, it activate the same cube....). and i don't want to repeat it. i searched on google and everywhere with no answers!

Please login or register to see this code.

Thank you everyone!

Edited by Logystone

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

OMA is correct. But another option is to have a list of indexes and remove/add indexes when you click the button and randomly select an index from the list of indexes. Tho while loops would work, it could cause possible hiccups depending on how many times the random number is continuously the same as the current index.

 

Although doing it the method I just explained CAN BE (not always) more efficient, it is also more complicated to understand if you haven’t messed with that sort of thing before

Share this post


Link to post
Share on other sites
  • 0

You think it is possible to get same number more then let's say 100 times, if random will be from 2+ numbers?
Even if somehow you will get same number 10 000 times, it is only 0.4 ms.

 

***

Edit: Did a test...
I was checking how many times i will get the same number:

Random.Range(0, 3);

From 50 000 times highest was 11 times.

 

Random.Range(0, 10);

From 60 000 times highest was 5 times.

 

 

Share this post


Link to post
Share on other sites
  • 0

@OneManArmy that’s why I stated in some cases. Depends on the complexity of the final product and the size and probability. Ran into this issue with the slot machine when I was randomizing symbols based on money in the machine. At one point on Android had a hiccup of almost half a second using the same while method because the probability factor was too low compared to the amount in the machine. Was more looking towards what his end product might be since we don’t really know how complex he’s wanting to go in the future

 

@Logystone good to hear

Share this post


Link to post
Share on other sites
  • 0

When someone needs help with so simple things, i don't think that end result will be something complex :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×