- Home /
Random place changement
What i'm trying to achieve is to make 3 cubes to randomly change on their positions. I was having problem with how to change different textures randomly on a cube but solved it. For example i have red, green and blue cube at static positions. How to make them randomly change their positions? Thank you.
Answer by jharger · Jul 22, 2011 at 07:43 PM
Well, it depends a little on where you want your cubes to end up. For example, if you want them to be placed within an axis-aligned box, you can use:
transform.position = new Vector3(Random.Range(minX, maxX),
Random.Range(minY, maxY), Random.Range(minZ, maxZ);
Where min(X|Y|Z) and max(X|Y|Z) are the extents of the box. If you want to constrain them within a sphere, you can use Random.insideUnitSphere. (See the Random class documentation for more examples)
Keep in mind that this does not ensure that the cubes do not overlap, as that is a more challenging problem.
Answer by TheKnight · Jul 22, 2011 at 07:55 PM
http://t1.ftcdn.net/jpg/00/11/81/64/400_F_11816493_9JAWSJFxTEheQAdZOB6tWrdKpy0X3mr2.jpg
Something like that. The cubes are positioned once and only once on one static place. So, when they are changed they are only changed in those 3 places.
P.S. - Post as a comment to this reply, i can't add comments.
Until you get >15 rep, no, you can't post comments on other people's answers. The preferable action is to edit or comment on your original question so that all the details are in one spot and it doesn't look like you have a dozen or so proposed solutions on your question already. In the future, please do so : )
Your answer
Follow this Question
Related Questions
cube texture change 0 Answers
I want to change the object position random in five particular position only. 0 Answers
Make a question and answer window 0 Answers
Creating a randomly generated texture on a plane. 1 Answer
change maincolor of texture 1 Answer