- Home /
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.
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;
Yea, localOffer is not empty. what values can I give for V3 and Q?
Do you want it to appear at a fixed position?
or do you want it to appear at a position of another object?
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?
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
![](https://koobas.hobune.stream/wayback/20220613094710im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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