void SpawnGhost(PlayerTrain playerTrain, Vector3 side) { GhostInfo info = new GhostInfo(); GameObject newGhost = Instantiate(ghostPrefab) as GameObject; newGhost.GetComponent <GhostController> ().feature = this; info.obj = newGhost; int wagonsCount = 0; for (int childIndex = 0; childIndex < playerTrain.transform.childCount; childIndex++) { if (playerTrain.transform.GetChild(childIndex).GetComponent <WagonScript>() != null) { wagonsCount += 1; } } WagonScript wagon = null; Transform spawnPoint = null; for (int wagonIndex = 0; wagonIndex < wagonsCount; wagonIndex++) { // try to get random wagon point wagon = playerTrain.GetWagon(Random.Range(0, wagonsCount)); spawnPoint = wagon.GetGhostPoint(); if (spawnPoint != null) { info.wagonIndex = wagon.GetIndex(); break; } wagon = playerTrain.GetWagon(wagonIndex); spawnPoint = wagon.GetGhostPoint(); if (spawnPoint != null) { info.wagonIndex = wagon.GetIndex(); break; } } //GameObject wagon = playerTrain.GetWagon (Random.Range(0,wagonsCount)).gameObject; if (spawnPoint == null) { return; } newGhost.transform.parent = spawnPoint; newGhost.transform.localPosition = new Vector3(0, 0, 0); newGhost.transform.localScale = new Vector3(1, 1, 1); newGhost.transform.localEulerAngles = side; newGhost.GetComponent <Animator>().Play("move"); spawnedGhosts.Add(info); }
void SpawnGhost(PlayerTrain playerTrain, Vector3 side) { GhostInfo info = new GhostInfo (); GameObject newGhost = Instantiate (ghostPrefab) as GameObject; newGhost.GetComponent<GhostController> ().feature = this; info.obj = newGhost; int wagonsCount = 0; for(int childIndex = 0; childIndex < playerTrain.transform.childCount; childIndex++) { if (playerTrain.transform.GetChild(childIndex).GetComponent<WagonScript>() != null) { wagonsCount += 1; } } WagonScript wagon = null; Transform spawnPoint = null; for (int wagonIndex = 0; wagonIndex < wagonsCount; wagonIndex++) { // try to get random wagon point wagon = playerTrain.GetWagon (Random.Range(0,wagonsCount)); spawnPoint = wagon.GetGhostPoint (); if (spawnPoint != null) { info.wagonIndex = wagon.GetIndex (); break; } wagon = playerTrain.GetWagon (wagonIndex); spawnPoint = wagon.GetGhostPoint (); if (spawnPoint != null) { info.wagonIndex = wagon.GetIndex (); break; } } //GameObject wagon = playerTrain.GetWagon (Random.Range(0,wagonsCount)).gameObject; if (spawnPoint == null) return; newGhost.transform.parent = spawnPoint; newGhost.transform.localPosition = new Vector3(0,0,0); newGhost.transform.localScale = new Vector3(1,1,1); newGhost.transform.localEulerAngles = side; newGhost.GetComponent<Animator>().Play("move"); spawnedGhosts.Add (info); }