Search Unity

Am I doing this right?

Discussion in 'Scripting' started by Deleted User, Apr 1, 2015.

  1. Deleted User

    Deleted User

    Guest

    I've spent lots of time making this game. To be quite honest it bugs me how long it has taken with so little to show for it. I want to ramp up the development. One thing I want to implement essentially a system of classes to instantiate for my game. Things like my player, my allies and enemies, other objects like planets and stations, inventory items, guns, bullets, etc. They also need to be extended so new ships, enemies, planets, etc. can be added automatically from a predefined file or prefab or something. Should I do that? Does unity do that for me already?

    Its all (OOP programming) really confusing. I don't want to spend $35 on a design patterns book and then read it instead of working on my game but I may if that's what is needed!

    What I have now is a player gameobject in a scene with a few control scripts attached. That's it.

    Perhaps someone could help clear my head... just super confused right now on what I need and how to do it. I don't need a complete code solution either. Just some advice...
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Unity works better if you think in terms of components, rather then strict inheritance.

    What does an alien do? It moves, shoots and takes damage. Therefore an alien is a GameObject with Move, Shoot and TakeDamage components.

    What does a player do? It takes player input, shoots, takes damage and collects coins. Therefore a player is a GameObject with... And so forth.
     
    TonyLi and Deleted User like this.
  3. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You can absolutely create GameObjects on the fly.

    Code (csharp):
    1.  
    2. GameObject character = new GameObject();
    3. character.AddComponent<Rigidbody>();
    4. character.AddComponent<AlienAi>();
    5. etc etc
    6.  
    But you might spend more time working out a system of laying out your objects in an XML or JSON file and creating them on the fly than you might spend just creating visual, tweakable prefabs.
     
    Deleted User likes this.