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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by AshwaniKumar · Mar 19, 2013 at 01:01 PM · prefabnguiruntime-generationdynamic loading

Add gameobject dynamically to scene in Unity3d

I am creating a scene in which I want to show list of offers. In order to show the offer, I created a prefab with placeholders for the offer details which I will get at runtime. I created a place holder in the scene to add the prefab to the scene, but it is not showing on the UI. OfferHolderClass: using UnityEngine; using System.Collections;

 public class OfferHolder : MonoBehaviour {
 
     public GameObject localOffer;
     // Use this for initialization
     void Start () {
         GameObject offer = Instantiate(localOffer) as GameObject;
         offer.GetComponent<Offer>().Text = "Testing";
         offer.transform.parent = this.transform;
     }
 
     // Update is called once per frame
     void Update () {
 
     }
 }

I am new to Unity and am not sure what I am missing here.

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 dorpeleg · Mar 19, 2013 at 01:37 PM

Make sure LocalOffer is not empty in the inspector.

You are also not giving a position to the Instantiate.

Try giving it a position like so:

 offer = Instantiate(localOffer, some V3, some Q) as GameObject;
Comment
Add comment · Show 4 · 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 AshwaniKumar · Mar 19, 2013 at 04:35 PM 0
Share

Yea, localOffer is not empty. what values can I give for V3 and Q?

avatar image dorpeleg · Mar 19, 2013 at 04:43 PM 0
Share

Do you want it to appear at a fixed position?

or do you want it to appear at a position of another object?

avatar image AshwaniKumar · Mar 19, 2013 at 05:13 PM 0
Share

Let me tell you my scenario. I have created NGUI Panel. In that I want to add Offer game object which is a prefab with dynamic data. So the number of offers in the panel can vary. I want it to be scrollable. Did you get the issue?

avatar image dorpeleg · Mar 19, 2013 at 06:00 PM 0
Share

I've never worked with NGUI so I don't know how it works.

Let's see if I can understnad.

You want your Offer gameobject to appear on the NGUI panel?

Is the NGUI panel an actual game object? or is it some sort of GUI element?

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

11 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

Related Questions

NGUI Sprite became invisible in prefab mode 0 Answers

Lighting Mapping the hard way 1 Answer

how to change the sprite of instantiated prefabs 1 Answer

Dynamic Scrollable List with NGUI 2 Answers

Injecting data into Prefabs 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