private void DrawLine() { if (is_inkMode == false || InkAmout.inkChack() == false) { return; } //マウスをクリックして線が始まる地点を決める if (Input.GetMouseButtonDown(0)) { //SceenPositionをWorldPositionへ変換 startPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); if (!draw_able()) { return; } is_Drawing = true; mouce_obj = Instantiate(Drawing_obj, startPos, Quaternion.identity); //list初期化 //---------------------------------------- Points.RemoveRange(0, Points.Count); Points_X.RemoveRange(0, Points_X.Count); Points_Y.RemoveRange(0, Points_Y.Count); Points_normal.RemoveRange(0, Points_normal.Count); } //マウスをドラッグして線が終わる地点を決める if (Input.GetMouseButton(0) && is_Drawing) { endPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); if (!draw_able()) { return; } //マウスを動かないとlistの追加をしない if (Vector2.Distance(tempPos, endPos) < 0.5f) { return; } Points.Add(endPos); Points_X.Add(endPos); Points_Y.Add(endPos); Drawing_obj.transform.position = endPos; mouce_obj.transform.position = endPos; tempPos = endPos; } //線を書きを終了する。 if (Input.GetMouseButtonUp(0) && is_Drawing) { Destroy(mouce_obj); is_Drawing = false; //-------------------- Points_X.Sort((s1, s2) => s1.x.CompareTo(s2.x)); //position.xを基準にして配列整列 Points_Y.Sort((s1, s2) => s1.y.CompareTo(s2.y)); //position.yを基準にして配列整列 Chack_Point_Normal(); //直線生成 if (lineClass.Chack_Line() && Points.Count < 10) { if (MaxLine > 3 || InkAmout.image.fillAmount < 0.3f) { return; } Instantiate(Wallparent, startPos, Quaternion.identity); InkAmout.decrease_Gauge(0.3f); MaxLine++; } //三角形を生成 else if (triangleClass.Chack_Traiangle(startPos, Points_Y[Points_Y.Count - 1], endPos) && Points.Count < 10) { if (InkAmout.image.fillAmount < 0.3f) { return; } float Tri_Height = Mathf.Abs((Points_Y[Points_Y.Count - 1].y - startPos.y)); float Tri_Width = Mathf.Abs((endPos.x - startPos.x)); float Tri_area = Tri_Height * Tri_Width / 2; Vector3 Center = Vector3.Lerp(startPos, endPos, 0.5f); var Tri_obj = Instantiate(Triangle, new Vector2(0, 0), Quaternion.identity); Tri_obj.GetComponent <Triangle>().HP = 10.0f; Tri_linRenderer = Tri_obj.GetComponent <LineRenderer>(); Tri_linRenderer.SetPosition(0, Center); Center.y += Tri_Height; Tri_linRenderer.SetPosition(1, Center); InkAmout.decrease_Gauge(0.3f); } // draw circle else if (circleClass.Chack_Circle(Points_normal)) { if (Points.Count < 8 || Points.Count > 20 || InkAmout.image.fillAmount < 0.5f) { return; } circle_center = new Vector2( (Points_Y[0].x + Points_Y[Points_Y.Count - 1].x) / 2, (Points_X[0].y + Points_X[Points_X.Count - 1].y) / 2 ); Instantiate(circle, circle_center, Quaternion.identity); InkAmout.decrease_Gauge(0.5f); } } }