// Use this for initialization void Start() { //Server need this link to assign purchased weapons body = GetComponent <Body_generic>(); cvar_watcher = FindObjectOfType <Server_watcher>(); main_camera = Camera.main; controller = GetComponent <Player_controller>(); if (!GetComponent <Player_controller>().isLocalPlayer) { enabled = false; return; } else//Continues as local player { if (cvar_watcher.map_type == CONSTANTS.MAP_TYPE.PVP) { //Menu menu = Instantiate(menu_prefab).GetComponent <Menu_watcher>(); menu.body = body; menu.buffer_inventory_size = body.inventory_size; if (body.isBot()) { menu.robot_menu.SetActive(true); menu.robot_submenu[controller.character_subtype].SetActive(true); menu.human_menu.SetActive(false); menu.zombie_menu.SetActive(false); menu.purchase_buttons = menu.purchase_buttons_robot; menu.upgrade_buttons = menu.upgrade_buttons_robot; menu.purchasables = cvar_watcher.purchases_robot; } else if (body.isHuman()) { menu.robot_menu.SetActive(false); menu.human_menu.SetActive(true); menu.human_submenu[controller.character_subtype].SetActive(true); menu.zombie_menu.SetActive(false); menu.purchase_buttons = menu.purchase_buttons_human; menu.upgrade_buttons = menu.upgrade_buttons_human; menu.purchasables = cvar_watcher.purchases_human; } else if (body.isZombie()) { menu.robot_menu.SetActive(false); menu.human_menu.SetActive(false); menu.zombie_menu.SetActive(true); menu.zombie_submenu[controller.character_subtype].SetActive(true); menu.purchase_buttons = menu.purchase_buttons_human; menu.upgrade_buttons = menu.upgrade_buttons_zombie; menu.purchasables = cvar_watcher.purchases_zombie; } menu.purchase_buttons_robot = null; menu.purchase_buttons_human = null; } cursor = Instantiate(cursor); cursor_anim = cursor.GetComponent <Animator>(); cursor_l = cursor.transform.Find("cursor_l"); cursor_r = cursor.transform.Find("cursor_r"); cursor_u = cursor.transform.Find("cursor_u"); cursor_d = cursor.transform.Find("cursor_d"); cursor_marker_sw = cursor.transform.Find("hit_marker_sw"); cursor_marker_se = cursor.transform.Find("hit_marker_se"); cursor_marker_nw = cursor.transform.Find("hit_marker_nw"); cursor_marker_ne = cursor.transform.Find("hit_marker_ne"); } GetComponent <Body_generic>().OnDamaged = damaged_screen; //HUD set-up //HUD_camera = Instantiate(HUD_camera, Vector2.zero, Quaternion.identity); //HUD_generic hud_generic = HUD_camera.GetComponent<HUD_generic>(); //HUD_camera.transform.parent = main_camera.transform; //HUD_camera.transform.position = main_camera.transform.position; HUD = Instantiate(HUD); HUD_generic hud_generic = HUD.GetComponent <HUD_generic>(); ammo_field = hud_generic.AmmoField; icon_field = hud_generic.ItemIcon; icon_field_anim = icon_field.GetComponent <Animator>(); overlay = hud_generic.Overlay; //ammo_field.GetComponent<MeshRenderer>().sortingLayerName = "HUD"; //Disable unwanted screen filters if (body.character_type == Body_generic.Character_type.Robot) { //Destroy(main_camera.GetComponent<ColorCorrectionCurves>()); Destroy(main_camera.GetComponent <BlurOptimized>()); //Destroy(main_camera.GetComponent<ContrastStretch>()); } else if (body.character_type == Body_generic.Character_type.Human) { Destroy(main_camera.GetComponent <NoiseAndGrain>()); Destroy(main_camera.GetComponent <VignetteAndChromaticAberration>()); } else if (body.character_type == Body_generic.Character_type.Zombie) { Destroy(main_camera.GetComponent <NoiseAndGrain>()); Destroy(main_camera.GetComponent <VignetteAndChromaticAberration>()); } }
// Use this for initialization void Start() { cvar_watcher = FindObjectOfType <Server_watcher>(); if (race == Body_generic.Character_type.Human) { cvar_watcher.team_human = this; } else if (race == Body_generic.Character_type.Robot) { cvar_watcher.team_robot = this; } else if (race == Body_generic.Character_type.Zombie) { cvar_watcher.team_zombie = this; } //set text if (text_counter != null) { text_counter.text = respawns_token.ToString(); } cvar_watcher.onClientReady.Add(OnClientReady); /* * //Find the player entity and register them to corresponding teams; If this fail to find players, players are going to find the team * //Let player/observer know of this entity, and making them check if this team members are spawn-ready * Player_controller[] players = FindObjectsOfType<Player_controller>(); * Debug.LogError("player number: "+players.Length); * for (int i = 0; i < players.Length; i++) * { * //Debug.LogError("found player: " + players[i].gameObject.name + " and his type: " + players[i].GetComponent<Body_generic>().character_type); * if (players[i].GetComponent<Body_generic>().character_type == race) * { * players[i].GetComponent<Body_generic>().team = this; * //Debug.LogError("player ready: "+ players[i].gameObject.name); * //body_ready++; * } * } */ //Server operations, spawn npc and assign team if (isServer) { alive = cvar_watcher.get_joined_character(race); if (alive <= 0) { enabled = false; } respawns_token = cvar_watcher.get_init_tickets(race); //Spawn npcs int number_to_spawn = alive - cvar_watcher.get_joined_player(race); //body_to_getReady = alive; //Rpc_tell_client_number(alive); for (int i = 0; i < number_to_spawn; i++) { int ran = UnityEngine.Random.Range(0, character.Length); GameObject npc = Instantiate(character[ran], transform.position, transform.rotation); //Debug.LogError("spawn: "+character[ran]); NetworkServer.Spawn(npc); Body_generic body_npc = npc.GetComponent <Body_generic>(); body_npc.cvar_watcher = cvar_watcher;//Needs to initialize on server side npc.GetComponent <Body_generic>().bodyRB = npc.GetComponent <Rigidbody2D>(); body_npc.OnRespawn = npc.GetComponent <AI_generic>().shopping; npc.GetComponent <AI_generic>().set_ai_condition(AI_generic.AI_condition.AGGRESSIVE); body_npc.team = this; //Make sure the upgrades are ready before shopping; if (body_npc.isHuman()) { body_npc.upgrades = cvar_watcher.upgrades_human; } else if (body_npc.isBot()) { body_npc.upgrades = cvar_watcher.upgrades_robot; } else if (body_npc.isZombie()) { body_npc.upgrades = cvar_watcher.upgrades_zombie; } npc.GetComponent <AI_generic>().body = body_npc; npc.GetComponent <AI_generic>().shopping(); //npc.GetComponent<AI_generic>().freeze_movement = true;//waiting for the preround to end npc.GetComponent <Body_generic>().character_cond = Body_generic.Character_condition.FROZEN; } } /* * if (isServer) * { * int percent = 100 / weapon.Length; * for (int i = 0; i < spawners.Length; i++) * { * spawners[i].spawn_limit = team_limit; * for(int j = 0; j < weapon.Length; j++) * { * spawners[i].equip_template.Add(new KeyValuePair<GameObject, int>(weapon[j], percent)); * } * spawners[i].npc_template.Add(new KeyValuePair<GameObject, int>(character, 100)); * } * } */ }