public void CreateCoral(Coral parent = null) { Coral coral; if (parent == null) { Debug.Log("START NEW ROOT CORAL"); coral = GameObject.Instantiate <Coral>(prefabCoral, LocateNewCoral(), Quaternion.identity); coral.depthLevel = 0; var random = (Vector2)Random.insideUnitCircle.normalized; Vector2 gravity = new Vector2(); #if UNITY_EDITOR gravity = debugGravity.normalized; #elif UNITY_ANDROID gravity = new Vector2(Input.gyro.gravity.x, Input.gyro.gravity.y).normalized; #endif var up = random + gravity * 2f; coral.transform.up = up.normalized; } else { // Debug.Log("NEW CORAL BRANCH"); coral = GameObject.Instantiate <Coral>(prefabCoral, Vector2.zero, Quaternion.identity); LocateCoralPart(coral, parent); coral.depthLevel = parent.depthLevel + 1; coral.parent = parent; parent.DropSeed(); } coral.sea = this; }
public void DropSeed() { if (!IsRoot()) { parent.DropSeed(); } else { seeds--; if (seeds <= 0) { this.hasStopped = true; this.gameObject.name += " IDLE-ROOT"; var allCorals = this.GetComponentsInChildren <Coral>(); foreach (var coral in allCorals) { coral.hasStopped = true; coral.gameObject.name += " STOPPED"; } } } }