Search Unity

newbie question on creating new objects

Discussion in 'Scripting' started by dacloo, Jan 27, 2006.

  1. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hi there,

    I'm really new to Unity and I only made one game in Blitz3d:

    (free download, see www.stickystudios.com)
    Enough pimping.

    I am used to scripting object oriented, Blitz style.
    When I want a new object of a certain type (struct), I would then type:

    p.player = new player();
    positionEntity p\entity, 0, 2, 0

    But how can I do this in Unity? For example when I want to shoot a bullet, how do I create this bullet fromout scripting (create a new instance of an object inside the project view)

    Thanks!
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  3. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    If you have declared your own new class then you can certainly create a new instance of it in the manner you suggest. (Create a new Unity script and it will set up the outline of such a class for you.)

    However, if you want to make a new object descended from GameObject, one that is visible in the Scene View and/or in the game itself, with Unity behaviors such as physics and shaders, you need to set up a prefab of your object, then make a copy of it using the Instantiate method. If you search the forums for "Instantiate" you will find other posts with more info. There are some subtleties with using GameObjects and the scripts attached to each one, probably worth reading some of those other posts.

    So for example in my game I have a prefab of a chess pawn with behavior scripts and gameobject components already attached to it, then I Instantiate as needed.
     
  4. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Thank you!

    Looks like an active, possitive community out here.
    We're gonna buy Unity Indie for now, hope to switch
    to Pro in the near future though.
    And, we have to buy a decent Mac for use with Unity.

    I was thinking of the Intel duo core Imac, my Powerbook
    G4 1.5ghz seems to be too slow for heavier 3d work.

    Best,

    Jeroen
     
  5. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
  6. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    It will be March before we see a version of Unity that runs on the Intel Macs, just FYI.
     
  7. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Thanks! Luckely I can use my 12" powerbook connecte to an external monitor for the time being! I will buy the Imac in March.