// Генерация фигуры public void next_figure() { figure = new Figure(); GameWnd game_wnd_comp = Display.game_wnd.GetComponent <GameWnd>(); game_wnd_comp.set_fig_icon(figure.fig_icon); StartCoroutine(timer_start()); }
// Апдейт void Update() { if (is_play == false) { return; } Vector3 mouse_pos = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Abs(camera.transform.position.z))); if (Input.GetMouseButton(0)) { if (Mathf.Abs(Input.GetAxis("Mouse X")) > mouse_sens || Mathf.Abs(Input.GetAxis("Mouse Y")) > mouse_sens) { is_move = true; timer_move = 0; particle.transform.position = mouse_pos; particle.emissionRate = 100; } else { timer_move += Time.deltaTime; if (timer_move > brush_sens) { if (is_move) { is_move = false; points.Add(mouse_pos); } } } } else if (Input.GetMouseButtonUp(0)) { float angle_sum = 0; Vector3 pos_sum = Vector3.zero; Vector3 center; for (int p = 1; p <= points.Count - 1; p++) { if (p <= points.Count - 2) { float angle = calc_angle(points[p - 1], points[p + 1], points[p]); angle_sum += angle; } else if (p == points.Count - 1) { } } for (int b = 0; b < points.Count; b++) { pos_sum += points[b]; } center = pos_sum / points.Count; if (points.Count > 0 && has_time == true) { float pt_dist = Vector3.Distance(points[0], points[points.Count - 1]); if ((angle_sum < 180 && angle_sum > 0) || (angle_sum > 180 && points.Count > 4)) { /*GameObject a = Instantiate(Resources.Load(Config.pref_inst_path + "Cube")) as GameObject ; * a.transform.position = points[0]; * a.name = "point 0"; * * GameObject a1 = Instantiate(Resources.Load(Config.pref_inst_path + "Cube")) as GameObject ; * a1.transform.position = points[points.Count-1]; * a1.name = "point 1";*/ if (pt_dist <= 2f && is_right(figure, center) == true) { StartCoroutine(Funcs.play_sound(gameObject, "fig_success")); GameWnd game_wnd_comp = Display.game_wnd.GetComponent <GameWnd>(); game_wnd_comp.add_score(); } else { StartCoroutine(Funcs.play_sound(gameObject, "fig_error")); } is_proc = false; } } reset(); } }
// Прогресс public IEnumerator timer_start() { is_proc = true; has_time = true; bool compl = false; float prog_val = timer_play; float rate = 1 / timer_play; float i = 0; GameWnd game_wnd_comp = Display.game_wnd.GetComponent <GameWnd>(); game_wnd_comp.set_timer_time("Timer: " + prog_val.ToString()); while (i < 1) { if (is_proc == true) { if (Math.Round(prog_val, 1) <= 0) { game_stop(); is_play = false; StartCoroutine(Funcs.play_sound(gameObject, "level_end")); yield break; } i += Time.deltaTime * rate; prog_val -= Time.deltaTime; game_wnd_comp.set_timer_time("Timer: " + Math.Round(prog_val, 1).ToString()); yield return(0); } else { compl = true; break; } } has_time = false; if (timer_play - timer_step >= 0) { if (compl == false) { StartCoroutine(Funcs.play_sound(gameObject, "fig_error")); } reset(); timer_play -= timer_step; next_figure(); } else { game_stop(); is_play = false; StartCoroutine(Funcs.play_sound(gameObject, "level_end")); } }