Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sos_willborn · Jul 05, 2017 at 08:50 AM · unity 5prefab-instance

Although prefabs has position, creating random position.

Hello, everyone I've issue about creating prefabs. Yesterday I asked same question but noone answer it. But I found something. I tryed when game running I look at the "scene". After I saw the prefabs creating random position. Let me show the photo.

alt text

this is what I will create

alt text

and it's game scene when prefab created. Why it happend? How can I solve?

Thanks in advance.

sss2.png (39.3 kB)
sss.png (276.7 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by merkaba48 · Jul 05, 2017 at 12:58 PM

How are you creating the prefab? If you're dragging and dropping into the scene view, it will place it 'somewhere' in view, not at the origin. If you drag/drop it into the hierarchy view, it will instantiate at the prefab's saved coordinates.

Comment
Add comment · Show 1 · 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 sos_willborn · Jul 05, 2017 at 03:04 PM 0
Share

I'm sorry for not share the code.

     public GameObject hazards;
     public Vector3 randomPosition;
 
     void Start () 
     {
         CallTheRandomRespawn ();
     }
     
     void CallTheRandomRespawn()
     {
         Vector3 position = new Vector3 (Random.Range(-randomPosition.x, randomPosition.x), randomPosition.z, randomPosition.z);
         Quaternion rotation = Quaternion.identity;
 
         Instantiate (hazards, position, rotation);
     }

I'm not create prefab with DnD, I'm create with code. I set the position but it's create random position.

Edit: I found my mistake, what a dumb fault. I have written randomPosition.x ins$$anonymous$$d of randomPosition.y

avatar image
0

Answer by Dyougi · Jul 05, 2017 at 04:02 PM

 Vector3 position = new Vector3 (Random.Range(-randomPosition.x, randomPosition.x), randomPosition.z, randomPosition.z);

Here the first argument of your new Vector3 (which is x) is set with Random.Range which is returning a random number depending of the range you specified. Instead of using this variable to set another one (Vector3 position), just use it when you instanciate your prefab

 Instantiate (hazards, randomPosition, rotation);

Since randomPosition is public, you can assign the position you want in the Inspector.

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

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

129 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 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 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 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 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 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

Click Events in Instantiated prefab does not work 2 Answers

How to display gameobject(prefab folder) as image? 1 Answer

Instantiating a new clone of a prefab whilst setting the previous clone as inactive 0 Answers

Hi I am trying to assign gameobject (prefab) from the List to another prefab gameobject but i think there is some mistake in one line of my code Please help. 1 Answer

Create a controller for a prefab that will live update all of the instances in the scene. 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