コード例 #1
0
    //Awake is always called before any Start functions
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            //if not, set instance to this
            instance        = this;
            movementoptions = Movemment.allmovement;
        }


        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }

        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);

        //Get a component reference to the attached BoardManager script
        boardScript = GetComponent <Map_script>();
        //Call the InitGame function to initialize the first level
    }
コード例 #2
0
    public void InitiatePlayer(global_game_controller game, Transform par)
    {
        global_game_controller = game;
        this.parent            = par;

        // initiate HUD & Map
        if (controll == Player_Controll.Player)
        {
            toggle_canvas = FindObjectOfType <toggle_canvas>();
            toggle_canvas.initiate(this);

            leveluppanel = FindObjectOfType <LevelUpPanel_Controller>();
            leveluppanel.initiate(this);

            playerhud = FindObjectOfType <PlayerHUDController>();
            playerhud.initiate(this);
            playerhud.updateAllLabels();
        }

        map_reference = GetComponentInParent <Map_script>();
        map_reference.initiate(this);

        initiated = true;
        controller.initiate(this);

        setDifficultDependent(controller.difficulty);
    }
コード例 #3
0
    void Start()
    {
        Time.timeScale = 0;
        string s = "";

        PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_controller(0), ref s, Player_Controll.Player.ToString(), true);
        PlayerPrefsHandler.SetPersistentVar <string>(Statics.player_controller(1), ref s, Player_Controll.Ai.ToString(), true);

        int player_amount = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_amount, 2);

        // Game Mode (only have one)
        //  string game_mode = PlayerPrefsHandler.GetPersistentVar<string>(Statics.game_mode, "1vs1");

        // Create entire gameworld
        for (int i = 0; i < player_amount; i++)
        {
            // create map
            Transform map = Instantiate(Resources.Load <GameObject>(map_prefab_path), new Vector3((Statics.map_x + Statics.map_space) * i, 0, 0), transform.rotation).GetComponent <Transform>();
            map_reference    = map.GetComponent <Map_script>();
            map_reference.id = i;


            // spawn and instantiate Player
            string player_prefab_path = "Players(ingame)/" + PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_character(i), "Mage");
            player = Resources.Load <GameObject>(player_prefab_path);
            Player p = Instantiate(player, map.transform.position + transform.up * 2, transform.rotation).GetComponent <Player>();

            // set player parent
            p.transform.SetParent(map);

            // set player name
            p.Name = PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_name(i), "Player1");


            // set controller
            string controller = PlayerPrefsHandler.GetPersistentVar <string>(Statics.player_controller(i), "Ai");
            if (controller == "Ai")
            {
                p.setController(Player_Controll.Ai);
                p.controller.setDifficulty(PlayerPrefsHandler.GetPersistentVar <string>(Statics.ai_difficulty(i), "Easy"));
            }
            else
            {
                p.setController(Player_Controll.Player);
                p.controller.setDifficulty(PlayerPrefsHandler.GetPersistentVar <string>(Statics.ai_difficulty(i), "Easy"));
            }
            diff_value.text = p.controller.difficulty.ToString();

            // get enemyparent and init player
            foreach (Transform t in map.GetComponentsInChildren <Transform>())
            {
                if (t.tag == "EnemyParent")
                {
                    p.InitiatePlayer(this, t);
                    break;
                }
            }

            // init camera
            camera_controller = map.GetComponentInChildren <Camera_Controller>();
            camera_controller.setTarget(p);

            // init game
            game_controller           = map.GetComponentInChildren <Game_Controller>();
            game_controller.MAX_ENEMY = PlayerPrefsHandler.GetPersistentVar <int>(Statics.enemy_amount, 50);
            enemy_limit.text          = game_controller.MAX_ENEMY.ToString();
            game_controller.initiate(p);

            // add to list
            Game_List.Add(game_controller);
        }

        global_camera = FindObjectOfType <global_camera_controller>();
        global_camera.initiate();

        // init menu
        inGameMenu.enabled    = false;
        extraQuestion.enabled = false;

        // get score
        int p1 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(0), 0);
        int p2 = PlayerPrefsHandler.GetPersistentVar <int>(Statics.player_score(1), 0);

        scoreboard.text = p1 + " : " + p2;
    }