void TrainInstantiation() { _allTrains = new GameObject[_playerNumber]; for (int i = 0; i < _playerNumber; i++) { bool tmpAvailableSpawningPosition = false; while (tmpAvailableSpawningPosition == false) { RailRoadScript tmpRailBlock = _railRoadScript[Random.Range(0, _railRoadScript.Count)]; if (tmpRailBlock._currentType == RailRoadScript.RailRoadType.OneWay || tmpRailBlock._currentType == RailRoadScript.RailRoadType.TurningPoint) { tmpAvailableSpawningPosition = true; _allTrains[i] = Instantiate(_trainPrefab, tmpRailBlock.transform.position, Quaternion.identity) as GameObject; _allTrains[i].name = "Train N°" + i; TrainScript tmpTrainScript = _allTrains[i].GetComponent <TrainScript>(); tmpTrainScript._owner = "Player" + i; if (i == 0) { tmpTrainScript._mainSprites.sprite = tmpTrainScript._engineSprites[0]; } else { tmpTrainScript._mainSprites.sprite = tmpTrainScript._engineSprites[1]; } tmpTrainScript._currentRailScript = tmpRailBlock; tmpTrainScript._currentWagonType = TrainScript.WagonType.Engine; tmpTrainScript._trainParts.Add(tmpTrainScript); tmpTrainScript._currentWagonNumber = tmpTrainScript._trainParts.Count - 1; tmpTrainScript.ComputeNextRailBlock(true); } } } }
//WAGON GENERATION---------------------------------------------------------------------------------------- public void WagonGeneration() { GameObject tmpWagon = Instantiate(GameManagerScript._instance._wagonPrefab, _trainParts[_trainParts.Count - 1]._previousRailScript.transform.position, Quaternion.identity) as GameObject; TrainScript tmpTS = tmpWagon.GetComponent <TrainScript> (); tmpTS._owner = _owner; tmpTS._currentWagonType = WagonType.Normal; _trainParts.Add(tmpTS); tmpTS._currentWagonNumber = _trainParts.Count - 1; foreach (TrainScript tp in _trainParts) { tp._trainParts = _trainParts; } tmpTS._isGeneratingWagons = false; if (_owner == "Player0") { tmpTS._mainSprites.sprite = tmpTS._player1WagonSprites[Random.Range(0, tmpTS._player1WagonSprites.Length)]; } else { tmpTS._mainSprites.sprite = tmpTS._player2WagonSprites[Random.Range(0, tmpTS._player2WagonSprites.Length)]; } tmpTS.ComputeNextRailBlock(true); }