Question by
ddiskyp · Sep 15, 2018 at 09:25 AM ·
globalinitialization
How to create global object on the game initialization?
Im a newb in unity in general and in scripting in particular but its really important for me to start work right and not dealing with copypasta later.
So i want to make a module system where i can grab some script with class inside and return instance of him for caller. For this thing i need some my own global method-controller of this process.
And here is the question: how i can create a global object with my methods for script-moduling system which must be visible in ANY other scripts just like native Input
object?
Comment
Answer by ddiskyp · Sep 15, 2018 at 10:22 AM
I handle this with creating an empty gameobject then put him on the top of hierarchy and add to him class with static method. Now i have my global controller.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mlf : MonoBehaviour {
public static string module(){
return "test";
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}