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 Bearukun · Apr 17, 2014 at 02:24 AM · prefabchildchild-to-gameobject

Adding child to a instantiated prefab.

Hi guys, I've been spending countless hours now with a problem that I can't get over without some help.

The basic idea behind the game is that I'm trying to make it so that I have this gameObject that, at some point, will spawn 3 additional bricks inside of it - I can get one bricks to spawn, but..!

     void CreateBlock(){
 
         
         b1 = Instantiate((blocks[Random.Range(0, blocks.Length)]), new Vector3 (-1.99f, 10.69f, 0), Quaternion.identity) as GameObject;
         
     
         b1.transform.parent = this.gameObject.transform;
         
 
 
 
     }

But the problem that I'm having is that I can't add the block I'm instantiating as a child to the prefab that I have added the script to.

I have zipped the project here, https://dl.dropboxusercontent.com/u/1148172/Zatch.zip if some kind soul would take a look at it.

Cheers.

Comment
Add comment · Show 2
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 Lachee1 · Apr 17, 2014 at 02:55 AM 1
Share

Looking at your code, it looks as if you are only instatiating a monobehaviour, try (blocks[Random.Range(0, blocks.Length)]).gameObject

avatar image Bearukun · Apr 17, 2014 at 10:28 AM 0
Share

It worked Lachee1! Thank you SO much..! :D

0 Replies

· Add your reply
  • Sort: 

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

Make a simple tree 1 Answer

How can I tell what prefabs a child object (script) is in? 2 Answers

[C#] An error occurs when trying to set a child to my GameObject in script. Why? 0 Answers

how to make prefab clone as a child of prefab clone? 0 Answers

Spawn Shield to all objects 2 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