Search Unity

If I have much gameObject in script is possible use other scrpt for simplify?

Discussion in 'Scripting' started by Kandrbol, Jun 26, 2019.

  1. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I have Start function up on the line about 500. Becouse I have much public GameObject. Is possible simplify example with other script? Mirek
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Maybe yes, maybe not. Is just pure guess game, for what you have provided us.
     
    DaemonicDreams likes this.
  3. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I need all object. Becouse it is database kit parts. I thinked something like with Vector3. In other game I had script with only Vector3 (1000 and more). Is possible script with database GameObject for GameManager?
     
  4. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    Can you use an array of GameObjects?
     
  5. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    For working with GameObject yes. But for inicialized I dont know. Every GameObject must write like public GameObject and insert in Inspector. It must be only in GameManager?
     
  6. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    I don't understand exactly what you are trying to do, something like this?
    Code (csharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.    public GameObject[] objectDatabase = new GameObject[];
    4. }
    And have every MyScript share the objectDatabase? You could use OnValidate
    Code (csharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.    public static List<GameObject> sharedDatabase = new List<GameObject>();
    4.  
    5.    public GameObject[] objectDatabase = new GameObject[];
    6.  
    7.    void OnValidate()
    8.    {
    9.        sharedDatabase.Clear();
    10.        foreach(var s in FindObjectOfType<MyScript>())
    11.        {
    12.           if(!sharedDatabase.Contains(s.gameObject))
    13.              sharedDatabase.Add(s.gameObject);
    14.        }
    15.    }
    16. }