/// <summary> /// アイテムをランダムに複数生成する /// </summary> public void InstantiateRandomItem(Vector3 pos, int num) { float angle = 360f / (float)num; for (int i = 0; i < num; i++) { int randNum = Random.Range(0, dropItemList.Length); GameObject g = Instantiate(dropItemList[randNum]); g.transform.parent = transform; g.transform.position = pos; Rigidbody r = g.GetComponent <Rigidbody>(); r.AddForce(FuncBox.DegreeToVector3(angle * i) * 1000f); } }
//サークルUIの生成 public void InstantiateCircle() { //割合計算と生成 contentsList = new List<CircleUIContents>();; float t = 0f; GameObject s; foreach (CircleValue p in circleValue) { //生成 s = (GameObject)Instantiate(prefab.gameObject); s.transform.parent = transform; s.transform.localPosition = Vector3.zero; s.transform.localScale = Vector3.one; contentsList.Add(s.GetComponent<CircleUIContents>()); //割合の母数を計算 t += p.per; } //正規化 float per = 0f; float addPer = 0f; float angle; float direction; Vector3 vec; normalizedPer = new List<float>(); for(int i = 0; i < circleValue.Count; i++) { //正規 per = circleValue[i].per / t; //角度 angle = 360 * addPer; addPer += per; normalizedPer.Add(addPer); //正規化リストに追加 //ずらす角度 direction = angle + (per * 360 / 2) + 90f; //座標をずらす vec = FuncBox.DegreeToVector3(direction); contentsList[i].transform.localPosition = vec * vecScale; //角度と割合 contentsList[i].transform.eulerAngles = new Vector3(0f, 0f, angle); contentsList[i].SetContents(per, circleValue[i].text); //名前 contentsList[i].name = "[" + i + "]"; } }
/// <summary> /// 角度移動 /// </summary> public void MoveAngle(Vector2 direction) { if (BreakCheck()) { return; } float angle = FuncBox.TwoPointAngleD(Vector2.zero, direction); //速度ベクトルの向きを変更 float fromAngle = FuncBox.TwoPointAngleD(Vector2.zero, rBody.velocity); float angleDistance = Mathf.Abs(Mathf.DeltaAngle(angle, fromAngle)); //角度差が一定範囲の場合でブーストしている場合 if (30 < angleDistance && angleDistance <= 170f && flagBoost) { float lerpAngle = Mathf.LerpAngle(fromAngle, angle, steering * Time.deltaTime); Vector3 velocityAngle = FuncBox.DegreeToVector3(lerpAngle); //速度の向き変更 rBody.velocity = velocityAngle * (rBody.velocity.magnitude); } //角度を設定 transform.eulerAngles = new Vector3(0f, 0f, angle); }