Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Nov 23, 2013 at 01:56 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Alanj2007 · Nov 16, 2013 at 10:45 PM · gameobjectpositionrandom

Random Position For GameObject

Using Unity Pro

If you notice in Slender game, there are 8 notes/pages and every time you play, page place in different places. I wanted to do that but I don't know how to make it.

I have 5 information/notes in my game (gameObject)

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
13
Best Answer

Answer by clunk47 · Nov 17, 2013 at 02:42 AM

Well, I agree the question is kind of broad and vague, but should not have been closed and considered off topic. Have a look at Random.Range, and use it for each axis on a Vector3. Say all your "notes" will be on the same Y position, but x and z will be random, just for example's sake.

 float x;
 float y;
 float z;
 Vector3 pos;

 void Start()
 {
     x = Random.Range(-25, 26);
     y = 5;
     z = Random.Range(-25, 26);
     pos = new Vector3(x, y, z);
     transform.position = pos;
 }




Comment
Add comment · Show 3 · Share
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 TaKoKaT · May 15, 2016 at 11:21 PM 0
Share

does this only work for x and z?

avatar image SplinterIsPurple TaKoKaT · Feb 05 at 11:50 PM 0
Share

Just change y = 5; to y = Random.Range(-25, 26);

avatar image TheCookieMan_ · May 26, 2020 at 03:26 PM 0
Share

Can you also use this for 2D games?

Follow this Question

Answers Answers and Comments

23 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 avatar image

Related Questions

spawn game object in random position 1 Answer

How can I calculate and place a GameObject at a random place just outside the camera frustrum? 0 Answers

Moving GameObject to various position ? 1 Answer

Spawn game object in random position on screen 1 Answer

Instantiate a GameObject at the position of one of its child objects 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