public void on_attacked(int attack_value) { Debug.Log("tower " + this.gameObject.name + " was attacked " + attack_value); attack_value -= this.config.defense; if (attack_value <= 0) { return; } this.blood -= attack_value; this.blood = (this.blood < 0) ? 0 : this.blood; this.ui_blood.set_blood((float)this.blood / (float)this.config.hp); if (this.blood <= 0) { this.is_lived = false; if (this.type == (int)TowerType.Main) { this.dead_anim.Play("death"); } else { this.gameObject.SetActive(false); } if (this.ui_blood && this.ui_blood.is_live) { GameObject.Destroy(this.ui_blood.gameObject); this.ui_blood = null; } } }
void OnDestroy() { if (this.ui_blood && this.ui_blood.is_live) { GameObject.Destroy(this.ui_blood.gameObject); this.ui_blood = null; } }
public UI_show_blood place_ui_blood_on_monster(int side) { GameObject ui = GameObject.Instantiate(this.UI_monster_blood_prefab); ui.transform.SetParent(this.transform, false); UI_show_blood blood = ui.GetComponent <UI_show_blood>(); blood.init(side); return(blood); }
private void place_monster(int type, int side, int road_index) { if (type < (int)MonsterType.Monster1 || type > (int)MonsterType.Monster3) { return; } if (side != (int)SideType.SideA && side != (int)SideType.SideB) { return; } if (road_index < 0 || road_index >= this.monster_roads.Length) { return; } if (type >= this.monster_prefabs.Length) // 没有对应小怪的资源 { return; } GameObject m = GameObject.Instantiate(this.monster_prefabs[type]); m.transform.SetParent(this.transform, false); monster_move agent = m.AddComponent <monster_move>(); Vector3[] road_data = null; if (side == (int)SideType.SideA) { road_data = this.road_data_set[road_index].path_sideA; } else { road_data = this.road_data_set[road_index].path_sideB; } monster mon = m.AddComponent <monster>(); mon.init(type, side, m.GetComponent <CapsuleCollider>().radius, road_data, agent); this.monsters.Add(mon); //创建要给ui血条 UI_show_blood ui_blood = this.ui_blood_mgr.place_ui_blood_on_monster(side); mon.ui_blood = ui_blood; //end }
private hero place_hero_at(PlayerMatchInfo match_info, int index) { int side = match_info.side; user_info uinfo = ugame.Instance.get_user_info(match_info.seatid); GameObject h_object = GameObject.Instantiate(this.hero_characters[uinfo.usex]); h_object.name = uinfo.unick; h_object.transform.SetParent(this.transform, false); Vector3 center_pos; if (side == 0) { center_pos = this.map_entry_A.transform.position; } else { center_pos = this.map_entry_B.transform.position; } if (index == 0) { center_pos.z -= 3.0f; } else { center_pos.z += 3.0f; } h_object.transform.position = center_pos; hero ctrl = h_object.AddComponent <hero>(); ctrl.is_ghost = (match_info.seatid != ugame.Instance.self_seatid); ctrl.logic_init(h_object.transform.position); ctrl.seatid = match_info.seatid; ctrl.side = side; //创建要给ui血条 UI_show_blood ui_blood = this.ui_blood_mgr.place_ui_blood_on_hero(side); ctrl.ui_blood = ui_blood; //end return(ctrl); }
private void place_towers() { tower t; //side A t = this.A_tower_objects[0].AddComponent <tower>(); t.init((int)SideType.SideA, (int)TowerType.Main, 4.0f); this.towers.Add(t); // 主塔 this.A_tower_objects[0].name = "A_main_tower"; // 创建要给ui血条 UI_show_blood ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideA); t.ui_blood = ui_blood; // end t = this.A_tower_objects[1].AddComponent <tower>(); t.init((int)SideType.SideA, (int)TowerType.Normal, 3.14f); this.towers.Add(t); // left this.A_tower_objects[1].name = "A_left_tower"; // 创建要给ui血条 ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideA); t.ui_blood = ui_blood; // end t = this.A_tower_objects[2].AddComponent <tower>(); t.init((int)SideType.SideA, (int)TowerType.Normal, 3.14f); this.towers.Add(t); // right this.A_tower_objects[2].name = "A_right_tower"; // 创建要给ui血条 ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideA); t.ui_blood = ui_blood; // end t = this.A_tower_objects[3].AddComponent <tower>(); t.init((int)SideType.SideA, (int)TowerType.Normal, 1.60f); this.towers.Add(t); // front this.A_tower_objects[3].name = "A_front_tower"; // 创建要给ui血条 ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideA); t.ui_blood = ui_blood; // end //end //side B t = this.B_tower_objects[0].AddComponent <tower>(); t.init((int)SideType.SideB, (int)TowerType.Main, 4.0f); this.towers.Add(t); // 主塔 this.B_tower_objects[0].name = "B_main_tower"; ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideB); t.ui_blood = ui_blood; t = this.B_tower_objects[1].AddComponent <tower>(); t.init((int)SideType.SideB, (int)TowerType.Normal, 3.14f); this.towers.Add(t); // left this.B_tower_objects[1].name = "B_left_tower"; ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideB); t.ui_blood = ui_blood; t = this.B_tower_objects[2].AddComponent <tower>(); t.init((int)SideType.SideB, (int)TowerType.Normal, 3.14f); this.towers.Add(t); // right this.B_tower_objects[2].name = "B_right_tower"; ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideB); t.ui_blood = ui_blood; t = this.B_tower_objects[3].AddComponent <tower>(); t.init((int)SideType.SideB, (int)TowerType.Normal, 1.6f); this.towers.Add(t); // front this.B_tower_objects[3].name = "B_front_tower"; ui_blood = this.ui_blood_mgr.place_ui_blood_on_tower((int)SideType.SideB); t.ui_blood = ui_blood; //end }