Question by
Kur4ta · May 30, 2017 at 10:45 AM ·
spawning-enemiesswitch-case
how to start over to back the frist Switch again, when the Function Spown has been done , it should be back to the function initialization but it can't. thank in andvanced
using System.Collections; using System.Collections.Generic; using UnityEngine;
namespace CompleteProject { public class LcgRandom : MonoBehaviour {
public int x;
public int i = 0;
public int a;
public int xn = 0;
public int c;
public int m = 7;
public int lcg;
private EnemyHealth ambil;
public GameObject musuh;
//public GameObject spawnPoint;
public float SpawnAreaGive = 1f;
public enum State
{
idle,
initialization,
pernyataan,
kolerasi,
acak,
spown
};
public State state;
void Awake() {
ambil = GameObject.FindWithTag ("Enemy").GetComponent<EnemyHealth> ();
state = LcgRandom.State.initialization;
}
// Use this for initialization
IEnumerator Start () {
while (true) {
switch (state) {
case State.initialization:
initialization ();
break;
case State.kolerasi:
kolerasi ();
break;
case State.acak:
acak ();
break;
case State.spown:
spown ();
break;
}
yield return null;
}
}
// void Update (){
// if (ambil.currentHealth <= 0) {
// ambil.isDead = true;
// state = LcgRandom.State.initialization;
// }
// }
private void initialization(){
// if (!CheckMusuh ())
// return;
// if (!CheckSpawnPoint ())
// return;
if (ambil.currentHealth <= 0) {
state = LcgRandom.State.kolerasi;
}
}
private void kolerasi() {
c = ambil.NilaiCounter;
a = ambil.startingHealth;
state = LcgRandom.State.acak;
}
private void acak ()
{
x = ((a * xn) + c);
lcg = x % m;
xn = lcg;
state = LcgRandom.State.spown;
}
private void spown ()
{
if (lcg == 4) {
GameObject[] enemySpawns = GameObject.FindGameObjectsWithTag ("EnemySpawnPoint2");
foreach (GameObject spawnPoint in enemySpawns) {
int noOfEnemies = 3;
for (int j = 0; j <= noOfEnemies; j++) {
GameObject enemy;
enemy = Instantiate (musuh, new Vector3 (spawnPoint.transform.position.x + Random.Range (-SpawnAreaGive, SpawnAreaGive),
spawnPoint.transform.position.y + Random.Range (-SpawnAreaGive, SpawnAreaGive),
spawnPoint.transform.position.z + Random.Range (-SpawnAreaGive, SpawnAreaGive)),
spawnPoint.transform.rotation) as GameObject;
initialization();
}
}
}
}
} }
Comment
Your answer
Follow this Question
Related Questions
change object state using enum switch from another script 1 Answer
switch case statment 0 Answers
Problems with spawning in the right way 0 Answers