実現したいこと
プレーヤー以外のhp,mpバーも変動させたい
初心者で、調べてもわからなかったので質問します。
発生している問題
エラーメッセージなし
3対3のゲームで5体cpu用のプレハブを複製している為、参照したいオブジェクト名が被りHP,mpバーの表示がうまく機能していません
新たに4体ずつ名前を変えてプレハブを作るのも思いつきましたが、大変そうなので他にいい方法がないか探しています
該当のソースコード
public void Start() { if (D.play1 == true) { int value = Random.Range(1, 60 + 1); if (value <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemy, new Vector3(-46, 20, -59), Quaternion.identity); iti = false; migi = false; } if (value >= 11 && value <= 20) { GameObject enemy2 = (GameObject)Instantiate(Enemy, new Vector3(-46, 20, -65), Quaternion.identity); ni = false; migi = false; } if (value >= 21 && value <= 30) { GameObject enemy3 = (GameObject)Instantiate(Enemy, new Vector3(-46, 20, -71), Quaternion.identity); san = false; migi = false; } if (value >= 31 && value <= 40) { GameObject enemy4 = (GameObject)Instantiate(Enemy, new Vector3(260, 20, 129), Quaternion.Euler(0f, 180f, 0f)); hida = false; yon = false; } if (value >= 41 && value <= 50) { GameObject enemy5 = (GameObject)Instantiate(Enemy, new Vector3(260, 20, 135), Quaternion.Euler(0f, 180f, 0f)); go = false; hida = false; } if (value >= 51) { GameObject enemy6 = (GameObject)Instantiate(Enemy, new Vector3(260, 20, 141), Quaternion.Euler(0f, 180f, 0f)); roku = false; hida = false; } for (int i = 0; i < 5; i++) { if (ni == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(-46, 20, -65), Quaternion.identity); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(-46, 20, -65), Quaternion.identity); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(-46, 20, -65), Quaternion.identity); } ni = false; migi = false; } if (iti == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(-46, 20, -59), Quaternion.identity); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(-46, 20, -59), Quaternion.identity); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(-46, 20, -59), Quaternion.identity); } migi = false; iti = false; } if (san == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(-46, 20, -71), Quaternion.identity); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(-46, 20, -71), Quaternion.identity); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(-46, 20, -71), Quaternion.identity); } migi = false; san = false; } if (roku == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(260, 20, 141), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(260, 20, 141), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(260, 20, 141), Quaternion.Euler(0f, 180f, 0f)); } hida = false; roku = false; } if (go == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(260, 20, 135), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(260, 20, 135), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(260, 20, 135), Quaternion.Euler(0f, 180f, 0f)); } hida = false; go = false; } if (yon == true) { int value3 = Random.Range(1, 30 + 1); if (value3 <= 10) { GameObject enemy1 = (GameObject)Instantiate(Enemycpu, new Vector3(260, 20, 129), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 21) { GameObject enemy1 = (GameObject)Instantiate(Enemy2cpu, new Vector3(260, 20, 129), Quaternion.Euler(0f, 180f, 0f)); } if (value3 >= 11 && value3 <= 20) { GameObject enemy1 = (GameObject)Instantiate(Enemy3cpu, new Vector3(260, 20, 129), Quaternion.Euler(0f, 180f, 0f)); } hida = false; yon = false; } } D.paly1 = false; } } }
補足
一部略で1キャラの例を載せました
unity.2019.40.f1
C♯
回答1件
あなたの回答
tips
プレビュー