Search Unity

How consist of script object at scene?

Discussion in 'Scripting' started by leegod, Oct 27, 2020.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    I do like this, but have no idea this is properly or not.

    Any comments?

    Divided 4 script objects because there are so many scripts attached to one script object.

    script-reference-structure.JPG
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    I don't understand the question.
     
    Vryken and PraetorBlue like this.
  3. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    With that many scripts, I think separating them into multiple objects is helpful. If nothing else, it's less to scroll through and you can organize by category.
    The other option is to have larger scripts with more functions. There are pros and cons to each. I tend to have one large main script with a ton of functions, and a moderate number of small scripts to handle the rest.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Do you actually need to put ANY of those in the scene? They don't seem to have any data or predefined state associated with them.

    I prefer the singleton approach.

    Some super-simple Singleton examples to take and modify:

    Simple Unity3D Singleton (no predefined data):

    https://pastebin.com/SuvBWCpJ

    Unity3D Singleton with Prefab used for predefined data:

    https://pastebin.com/cv1vtS6G

    These are pure-code solutions, do not put anything into any scene, just access it via .Instance!
     
  5. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    I don't put out script that only have class and functions.

    But most of scripts has variable that reference from scene....

    Because it should control the game UI component, data.

    and I am already using

    public class scriptname : singleton<scriptname>

    from copied singleton class code got somewhere in this forum.