void Start() { VeinTrain[] trains = GameObject.FindObjectsOfType(typeof(VeinTrain)) as VeinTrain[]; foreach (VeinTrain train in trains) { // only one train should be tagged "Player" at a time... find it! if (train.tag == "Player") { parentTrain = train; break; } } // initialize the next artery and next train Debug.Log(name + " calling " + parentTrain.nextArtery.name + "'s GenerateBranches();"); parentTrain.nextArtery.GenerateBranches(); parentTrain.TransitionToNextArtery(); parentTrain.GenerateNextTrain(); }
public void GenerateNextTrain() { if (nextTrain != null) { Debug.Log("ERROR: " + name + " asked to re-generate next train"); return; } else { Debug.Log(name + " generating next train"); } // figure out where to spawn the next train float nextTrainProgress = pathProgress + 0.25f; Vector3[] nextTrainPath = path; if (nextTrainProgress >= 1f) { nextTrainProgress -= 1f; nextTrainPath = nextArtery.path.nodes.ToArray(); } Vector3 pointOnPath = iTween.PointOnPath(nextTrainPath, nextTrainProgress); Vector3 lookTarget = iTween.PointOnPath(nextTrainPath, nextTrainProgress + 0.01f); // pick the prefab Object randomPrefab = trainPrefabs[Random.Range(0, trainPrefabs.Length)]; // spawn and let itween place it just so... GameObject go = Instantiate(randomPrefab) as GameObject; VeinTrain train = go.GetComponent<VeinTrain>(); iTween.MoveUpdate(go, iTween.Hash("position", pointOnPath, "looktarget", lookTarget, "time", 0)); train.path = nextTrainPath; train.pathProgress = nextTrainProgress; train.nextArtery = nextArtery; nextTrain = train; }
public override void OnEnter() { trainToDelete = ship.parentTrain; ship.parentTrain = ship.parentTrain.nextTrain; ship.parentTrain.GenerateNextTrain(); ship.transform.parent.parent = null; ship.StartCoroutine(WaitAndSetParent()); }