• 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 /
  • Help Room /
avatar image
-1
Question by Zitoox · Oct 23, 2016 at 03:09 AM · prefabspawningsphereinsideminigame

Random spawn script

Hi! This is a complicated thing and i am just a beginner at scripting, so please be pacient. As i mentioned in a question before, i am making a party scene in my game, and there is a minibar on it. The minibar has a lot of drinks, and there are 3 cups. I wanted to do a minigame, in wich when you hit the trigger of the cups you enter in a scene in wich you need to guess the right cup and then you will get a trophy.

I already did the thing about making the character go to the scene, and i plan to do the trophy later. My problem is with the minigame itself! I have 3 cups, and i want a sphere to randomly spawn in one of the cups and then be a child of it. But my knowledge about spawning is terrible and i never understood how to get an object to be child of another using scripts. Could someone lend me a hand here? I would be very grateful =]

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by b1gry4n · Oct 23, 2016 at 04:07 AM

     public Transform[] cups;
     public GameObject ballPrefab;
 
     int chosen = Random.Range(0, cups.Length);
     GameObject ball = (GameObject)Instantiate(ballPrefab, cups[chosen].position, Quaternion.identity);
     ball.transform.parent = cups[chosen];

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

68 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

Related Questions

Unet Spawn Prefabs When Scenes Changes 0 Answers

Problem spawning prefabs client side, stand alone build. 0 Answers

Characters not attaching to prefab location when spawned? 0 Answers

How to make a prefab spawn on the same spot on a rotating object? 1 Answer

How to spawn a prefab every 5 second randomly between a set range? 0 Answers

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