Search Unity

How to attach model to gameobject in script?

Discussion in 'Scripting' started by prophet, Jun 30, 2012.

  1. prophet

    prophet

    Joined:
    Sep 8, 2009
    Posts:
    211
    So, I am having issues trying to figure out how to attach and show a model when I load a menu. I apparently can create the object, just cant seem to find the info to attach my model to it.

    The object I declared shows up in unity inspector and I can assign a model to it, but I never see it when I click play. And advice?

    Here is the small bit of code I have creating the object. Not sure if more is needed.

    Code (csharp):
    1.  
    2. var baseCharacter : GameObject;
    3.  
    4. baseCharacter =  new GameObject ("baseCharacter");
    5. baseCharacter.transform.Translate(0,-231,-431);
    6. baseCharacter.transform.localScale += Vector3(100,100,100);
    7. baseCharacter.active = true;
    8.  
     
  2. hafizmrozlan

    hafizmrozlan

    Joined:
    Jun 15, 2012
    Posts:
    117
    It looks like you haven't "instantiate" your gameObject yet. That's why you can't see it.
     
  3. prophet

    prophet

    Joined:
    Sep 8, 2009
    Posts:
    211
    When I try to instantiate the object it just create a clone of the object it creates. Maybe I dont explain myself well :/

    When I start the game, an empty game object shows up under Hierarchy, but no model attached to it.
     
  4. siflandolly

    siflandolly

    Joined:
    May 17, 2011
    Posts:
    141