• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Using HashSet in Unity 3 Answers

OrderedDictionary in System.Collections.Generic for mobile 0 Answers

Appear after set number of seconds 2 Answers

Random object appearance in specific length and height 1 Answer

How to make a game object ONLY to appear in game startup? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges