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 SirBoboHobo · Apr 02, 2015 at 05:53 PM · c#instantiateprefabrandomvertical

instantiating vertically

Im making a platformer and made 14 prefabs, each is made of game objects with a collider and trigger attached to them, my player jumps up on platforms, i want to instantiate those 14 prefabs vertically, one after another prefab. I thought of attaching a trigger to the camera that checks if there are any platforms in the area the trigger will cover, if not instantiate. anyone can help? give me any ideas??

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
2

Answer by Digital-Phantom · Apr 01, 2015 at 07:02 AM

Put a trigger on each platform so each time your player jumps onto a platform the next on is instantiated

Better yet put your 14 prefabs into an array and then pick on randomly. That way no two play-throughs of your game would be the same

:)

Or make them instantiate by using a yield WaitForSeconds statement so a new prefab appears every few seconds.

Or even just keep track of the players position on the Y axis and instantiate a new prefab as the player moves upwards.

;)

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 SirBoboHobo · Apr 01, 2015 at 12:11 PM 0
Share

Or even just keep track of the players position on the Y axis and instantiate a new prefab as the player moves upwards. That's exactly what I'm looking for, could you help me on this one tho? how would the code look? I'm frustrated and confused >.<

avatar image Digital-Phantom · Apr 01, 2015 at 12:21 PM 0
Share

Still fairly new to this myself but something along the lines of-

 if(transorm.position.y >=10)
 {
   Instantiate(yourPreFab, transform.position.y+10, transform.rotation);
 }
 

Then do additional if >= for 20, 30 and so on...

There is probably a way to do that programmatically in a single if statement, but like I said I'm still quite new to this myself.

avatar image SirBoboHobo · Apr 01, 2015 at 12:48 PM 0
Share

arg, could be problematic since each prefab is different size tho. I dont want there to be gaps between prefabs or it wont be playable, and also dont want them to generate one on another if the distance is too short... I have no ideas tho :/

avatar image
0

Answer by SamiSiddiqui · Apr 02, 2015 at 06:07 PM

I guess you want some kind of pooling at work. Instantiate Object is player is in range? There are alot of ways to do that. I suggest Instantiate all Objects at start and display when they are required. For the display you can create a JSON file or something to store x,y of platforms in your level. Then check player y and load platforms which are near to player you can take a constant value to subtract and add to player y to get the list of platforms needs to created. But if you want it to precise you can get on start Camera World Top and Camera World Bottom (http://docs.unity3d.com/ScriptReference/Camera.ViewportToWorldPoint.html). Then Add/Subtract that from player y.

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

21 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

Related Questions

instantiate random prefabs based on player camera distance 1 Answer

Can't set the random position for an Instance. 1 Answer

How To NOT Instantiate the same Prefab Twice (C#) 1 Answer

Prefab Particle clones won't destroy, C# 1 Answer

How to create new tail in a simple 3D Snake 0 Answers


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