private void OnTriggerEnter(Collider other) { if (other.tag == "StellarBody") { StellarBodyModel otherModel = other.GetComponent <StellarBodyModel>(); if (other.name.Contains("BlackHole")) { // make sure we don't eat the one we are placing if (stellarBodyModel.timeCreated < otherModel.timeCreated) { _stellarBodyController.ThisEatsThat(otherModel, stellarBodyModel); } else { _stellarBodyController.ThisEatsThat(stellarBodyModel, otherModel); } } else { _stellarBodyController.ThisEatsThat(stellarBodyModel, other.GetComponent <StellarBodyModel>()); } } else if (other.tag == "Ship") { _stellarBodyController.ThisEatsShip(stellarBodyModel, other.GetComponent <ShipModel>()); _shipController.ShipAte(); } else if (other.tag == "Asteroid") { _stellarBodyController.AddMassTo(stellarBodyModel, other.GetComponent <AsteroidModel>().mass); } }
private IEnumerator _StartBlackHolePlace(Vector3 mousePosition) { if (_stellarBodyController != null) { // initialize GameObject blackHole = Instantiate(blackHolePrefab); blackHole.transform.parent = blackHoleContainer; blackHole.transform.localScale = Vector3.one * startSize; Vector3 position = camera.ScreenToWorldPoint(mousePosition); position.z = 0; blackHole.transform.position = position; StellarBodyModel stellarBodyModel = blackHole.GetComponent <StellarBodyModel>(); stellarBodyModel.mass = startMass; // add the black hole to the stellar body controller _stellarBodyController.AddBody(stellarBodyModel); // wait until release while (Input.GetMouseButton(0)) { // slowly grow the black hole stellarBodyModel.mass += massGrowthRate * Time.deltaTime; stellarBodyModel.transform.localScale = Vector3.one * stellarBodyModel.mass / 5.0f; yield return(null); } } }
public IEnumerator _Grow(StellarBodyModel model) { while (gameObject) { model.mass += 0.4f; model.transform.localScale = Vector3.one * model.mass / 5.0f; yield return(null); } }
private void _DestroyAllBlackHoles() { BlackHoleModel[] blackHoles = FindObjectsOfType <BlackHoleModel>(); for (int i = 0; i < blackHoles.Length; i++) { StellarBodyModel model = blackHoles[i].GetComponent <StellarBodyModel>(); _stellarBodyController.RemoveBody(model); Destroy(blackHoles[i].gameObject); } }
private void _Initialize() { // spawn our planets for (int i = 0; i < planetConfig.childCount; i++) { Transform state = planetConfig.GetChild(i); GameObject planet = Instantiate(planetPrefab); planet.transform.parent = planetContainer; planet.transform.position = state.position; planet.transform.localScale = state.localScale; planet.GetComponentInChildren <Renderer>().material.color = new Color( state.localEulerAngles.x, state.localEulerAngles.y, state.localEulerAngles.z ); StellarBodyModel model = planet.GetComponent <StellarBodyModel>(); if (i == startList[startIndex]) { //GameObject start = Instantiate(startPrefab); //start.transform.parent = planet.transform; //start.transform.localPosition = new Vector3(0, 0, -3); } if (i == targetList[targetIndex]) { model.isTarget = true; // indicate the target //GameObject target = Instantiate(targetPrefab); //target.transform.parent = planet.transform; //target.transform.localPosition = new Vector3(0, 0, -3); } else { model.isTarget = false; } if (!string.IsNullOrEmpty(planetLabels[i])) { GameObject label = Instantiate(planetLabel); label.transform.parent = planet.transform; label.transform.localPosition = new Vector3(0, 0, -4); TextMesh text = label.GetComponentInChildren <TextMesh>(); text.text = planetLabels[i]; if (!notNeeded.Contains(i)) { model.isNeeded = true; } } model.mass = planet.transform.localScale.x * 10; _stellarBodyModels.Add(planet.GetComponent <StellarBodyModel>()); } }
public void ThisEatsThat(StellarBodyModel one, StellarBodyModel two) { if (!_stellarBodyModels.Contains(one) || !_stellarBodyModels.Contains(two)) { return; } one.mass += two.mass; one.transform.localScale = Vector3.one * one.mass / 5.0f; if (two.isNeeded) { StartCoroutine(_Grow(one)); } _stellarBodyModels.Remove(two); Destroy(two.gameObject); }
private void OnTriggerEnter(Collider other) { StellarBodyModel model = other.GetComponent <StellarBodyModel>(); if (model) { if (model.isTarget) { // win if (!levelComplete) { _stellarBodyController.ActiveModelNotNeeded(); _gameStateController.LevelComplete(); levelComplete = true; } } } }
public void AddMassTo(StellarBodyModel one, float mass) { one.mass += mass; one.transform.localScale = Vector3.one * one.mass / 5.0f; }
public void ThisEatsShip(StellarBodyModel one, ShipModel ship) { one.mass += 0.5f; one.transform.localScale = Vector3.one * one.mass / 5.0f; }
public void AddBody(StellarBodyModel model) { _stellarBodyModels.Add(model); }
public void RemoveBody(StellarBodyModel model) { _stellarBodyModels.Remove(model); }