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 JessicaSwadling · Aug 30, 2016 at 08:09 AM · c# tutorialappearcollections

How to make an object appear when another is collected?

Hi, i'm new to unity, I have made roll-a-ball game following the tutorials on unity. now i want change it so only 2 pick up objects are displayed when you open the game and then when you collect them another 2 of the pick up objects appear. Please help me!

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
1

Answer by juicyz · Aug 30, 2016 at 05:16 PM

I haven't looked at the tutorial yet but I'm guessing the amount of objects are predefined, as in they are all created at initialization of the game by the Scene and not Script.

There are many ways to do this.

1- Spawn in the objects into the Scene and have a list of all the pickup objects.

  • This involves setting them all as 'SetActive(false)' then randomly selecting two at the beginning and doing a 'SetActive(true)'

2- Use the GameObject.Find methods on 'Picks Ups' and select which children you want to set asActive

3- etc

Next have a counter of some sort that increments when a player hits a pick up object, in your Update function, you can check if the counter is equal to 2, then set two random pick up objects as 'SetActive(true)'

If you need actual code code, I can write that too but figuring it out on your own is much more fun.

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 JessicaSwadling · Aug 31, 2016 at 11:29 PM 0
Share

Hi thanks so much for the reply! i have created the SetActive(false) and put the scrip attached it the the parent and its working! but i don't know how to select 2 objects to make SetActive(true)?

avatar image juicyz JessicaSwadling · Sep 01, 2016 at 01:25 AM 0
Share

How are your objects organized?

  • Do you have an array or list of them somewhere in code? If you do, then you can select from this list randomly using something like: int random = (int)(Random.value() * (array length)) Do this, set the object to active, do this again and set object to active

  • Are they just placed in the game by drag and drop? You could gather the objects by using a Find method and setting it to active, then getting another and setting it to active

avatar image
1

Answer by Cynikal · Aug 30, 2016 at 05:53 PM

The simplest solution to this that I can think of, is as follows:

Make a Game Manager empty gameobject on your scene. Make a GameManager script for said game object.

In your GameManager, have an array of predetermined objects to pick up.

In your pickup objects, when you collide, call a function on GameManager that they've been picked up. Disable the pickup object.

On GameManager, when called "PickedUp" function, add your points or whatever, then randomly select 2 gameobjects from the array and enable them.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I need a good data structure collection for Unity, where can I find it? 2 Answers

Dictionary suddenly loses its items 1 Answer

Simple appear trigger not working for me 1 Answer

Make object appear within camera view 0 Answers

how can compare the the character by ascii value ? 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