Search Unity

Which option for scripting 3 objects is the best?

Discussion in 'Scripting' started by DarkTulip, Feb 18, 2018.

  1. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    Hi all,

    I have 3 game objects next to each other. Let's call them objA, objB, and objC. They have to do a lot of similar things and have to wait for each other to execute some action. For example, they all start moving at the same time but only after objA has stopped moving objB can stop and so on.

    Which option is best and why?

    1) Give each object its own script. (scriptA, scriptB, and scriptC)
    2) Give all the objects the same script. (3x scriptABC)
    3) Place the 3 objects in an empty game object and place a script on that. (1x scriptABC)

    Thank you in advance.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Are they all capable of doing the same actions? How long do they have to wait, after 1 object is done?

    Your question is a little vague. Have you previously tried to organize this and felt stumped?

    Say they can all move and change colour. It could be the same script on each game object. Now, if I wanted to control that they begin and/or end their actions in order, I might have another script that takes care of that.
     
  3. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    Thank you for your reply. I listened to your advice in another thread and stopped this game for now. I started with a really simple game instead. This way I can be sure I will finish it and finally after years have my first finish game and not being that "idea guy" anymore :)
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ah okay, right on. :) Enjoy!