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
1
Question by theJuls · Jan 11, 2012 at 05:38 PM · randomobjectspickups

Generating pickups randomly

First of all, I must warn you I am quite a newbie on Unity, so please excuse my dumb questions. Anyway, I am developing a 2D platform game (similar do Robot Unicorn Attack), and I need to generate pickup items (like coins) randomly on the platforms. Problem is I have no idea how to do that. I already made my pickups, but they are the kind we manually place them on the screen. What I want to do is during the game, once the platform is visible, generate the pickups randomly. Thank you very much for your help.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by asafsitner · Jan 11, 2012 at 05:48 PM

Make an array to hold your pickup prefabs, and place empty game objects above your platforms, where you want the pickups to be. You can make them children of the platform so it'll be easier to find them. Have a script on the platform that determine when the platform is visible, that holds the pickup locations in an array of it's own, then iterates over it and randomly chooses a pickup prefab from the pickups array.

You can hold the pickups array in an external class and reference it from every platform. Or you can have an array for each platform for greater control.

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

Answer by Larry-Dietz · Jan 11, 2012 at 05:56 PM

Without knowing more about the way you are coding this, the best answer I can give you is to look at the following...

Instantiate

The Instantiate command will let you create objects in the game world on the fly.

Hope this is of some help.

-Larry

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

Answer by Muzz5 · Jan 11, 2012 at 06:15 PM

 var prefab : GameObject;
 var spawns = GameObject.FindGameObjectsWithTag ("spawn");
 for (var spawnSpot in spawns)
     Instantiate (prefab, spawnSpot.transform.position, spawnSpot.transform.rotation);

There you go. Spawns an object at all places tagged spawn

Comment
Add comment · Show 2 · 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 ani2020.bhandari · Dec 20, 2012 at 04:33 PM 0
Share

UnityException: You are not allowed to call this function when declaring a variable.

What To Do ????

avatar image rangapraveen · Aug 02, 2013 at 08:44 AM 0
Share

hey , i tried using this piece of code.It doesn't just spawn one object , but multiple copies of it (like in an infinite loop)..what to do ?

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

10 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

Related Questions

A node in a childnode? 1 Answer

Generating objects randomly, only one will Instantiate 0 Answers

Instantiate Random Object at Random Position 1 Answer

my random task generator not working 1 Answer

How to snap object to terrain after already placed in scene? 3 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