public void ChangeTarget(int type) { for (int i = 0; i < num; i++) { var t = targets[i]; if (type == 0) { t.x = (i % 8f - 3.5f) * 10f + 3.5f * (Random.value - 0.5f); // + t.z = Random.Range(-50f, 50f); } else if (type == 1) { t.x = Random.Range(-50f, 50f); t.z = Random.Range(-50f, 50f); } else { var pp = ImgPos.GetRandomPoint(); t.x = -pp.x / 2f; t.z = -pp.y / 2f; if (Random.value < 0.3f) { t.x = Random.Range(-50f, 50f); t.z = Random.Range(-50f, 50f); } } targets[i] = t; } }
private void Update() { //マウスが押されたら、適当にターゲット位置を入れ替える if (Input.GetMouseButtonDown(0)) { var flag = Random.value < 0.5f ? true : false; var flag2 = Random.value < 0.3f ? true : false; Debug.Log("mousedown"); for (int i = 0; i < num; i++) { var t = targets[i]; if (flag) { t.x = (i % 8f - 3.5f) * 10f + 10.5f * (Random.value - 0.5f); // t.z = Random.Range(-50f, 50f); } else { //t.x = Random.Range(-50f, 50f); //t.z = Random.Range(-50f, 50f); //Debug.Log("au"); var pp = ImgPos.GetRandomPoint(); t.x = -pp.x / 2f; t.z = -pp.y / 2f; if (Random.value < 0.3f) { t.x = Random.Range(-50f, 50f); t.z = Random.Range(-50f, 50f); } } t.y = 0;//Random.Range(-0.1f, 0.1f); if (flag2) { t.x = t.z = 0; } targets[i] = t; } } //足をじたばたする2コマぶんの計算 var n = (Mathf.FloorToInt(Time.frameCount * 0.2f) % 2); for (int i = 0; i < num; i++) { //位置の更新 var p = positions[i]; var t = targets[i]; var v = t - p; v = v / 20f; var lim = 0.1f + 0.05f * ((float)i / (float)num); if (v.magnitude > lim) { v = v.normalized * lim; } p += v; positions[i] = p; //uniformを1個ずつ指定 propertyBlock.SetFloat("_DT", i / 1000f); propertyBlock.SetColor("_Col", colors[i % colors.Count]); var q = Quaternion.Euler( new Vector3( 0, (-Mathf.Atan2(v.z, v.x) + Mathf.PI / 2f) / Mathf.PI * 180f, 0 ) ); //描画 Graphics.DrawMesh(m_mesh, p, q, m_mat, 0, null, 0, propertyBlock); //var mtx = new Matrix4x4(); // var mtx = Matrix4x4.Translate(p); //mtx.tr //Graphics.DrawMeshInstanced(m_mesh,0,m_mat,mtx,propertyBlock,true,false); } }