void Generate() { int size = levelCurve.childCount; UIManager.Instance.SetMaxPlatforms(size); for (int i = 0; i < size - 1; i++) { GameObject go = Instantiate(platformPrefab, levelCurve.GetChild(i).transform.position, Quaternion.identity); LevelPlatformInfo platformInfo = go.GetComponent <LevelPlatformInfo>(); platformInfo.textMesh.text = (size - 1 - i).ToString(); // Update the number platformInfo.number = (size - 1 - i); // Determine the type by random int rand = Random.Range(0, 100); if (rand > 80) { platformInfo.type = LevelPlatformInfo.PlatformType.Broken; platformInfo.bouncePower = 8; platformInfo.transform.GetChild(0).transform.GetChild(0).GetComponent <MeshRenderer>().material = brokenMat; } else { platformInfo.type = LevelPlatformInfo.PlatformType.Bounce; platformInfo.bouncePower = 10; } if (i > 0) // This ensures that the first iteration is ignored to avoid a out of bounds error. { var lookPos = go.transform.position - levelCurve.GetChild(i - 1).transform.position; // Face the next platform tothe previous platform. var rotation = Quaternion.LookRotation(lookPos); rotation.x = go.transform.rotation.x; rotation.z = go.transform.rotation.z; go.transform.rotation = rotation; } rand = Random.Range(0, 100); if (rand > 80) { platformInfo.feature = LevelPlatformInfo.FeatureType.Moving; } else { platformInfo.feature = LevelPlatformInfo.FeatureType.None; } go.transform.SetParent(transform); } GameObject finish = Instantiate(finishPrefab, levelCurve.GetChild(size - 1).transform.position, Quaternion.identity); finish.transform.SetParent(transform); }
private void OnCollisionEnter(Collision collision) { switch (collision.gameObject.tag) { case "Platform": LevelPlatformInfo platformInfo = collision.gameObject.transform.parent.parent.GetComponent <LevelPlatformInfo>(); bounce = true; power = platformInfo.bouncePower; platformInfo.Bounced(); //AddBounce(platformInfo.bouncePower); //Debug.Log(Vector3.Distance(transform.position, collision.gameObject.transform.position)); float distance = Vector3.Distance(transform.position, collision.gameObject.transform.position); if (platformInfo.number < current) { previous = current; current = platformInfo.number; UIManager.Instance.UpdateProgress(platformInfo.number); if (previous - current > 5) { UIManager.Instance.ShowLongJump(); fireFx.SetActive(false); } else if (distance > .5f && distance < .89f) { UIManager.Instance.ShowPerfect(); fireFx.SetActive(true); } else if (distance > .89f && distance < 1.6f) { UIManager.Instance.ShowGood(); fireFx.SetActive(false); } } Leaderboard.Instance.UpdateLeaderboard(current); switch (platformInfo.type) { case LevelPlatformInfo.PlatformType.Broken: platformInfo.isDestroyed = true; SoundManager.Instance.PlaySfx(SoundManager.Instance.brokenSfx); break; case LevelPlatformInfo.PlatformType.Bounce: SoundManager.Instance.PlaySfx(SoundManager.Instance.bounceSfx); break; } break; case "Spring": LevelPlatformInfo springInfo = collision.gameObject.transform.parent.GetComponent <LevelPlatformInfo>(); springInfo.Bounced(); //AddBounce(springInfo.bouncePower); bounce = true; power = springInfo.bouncePower; SoundManager.Instance.PlaySfx(SoundManager.Instance.springSfx); fireFx.SetActive(false); break; case "Finish": anim.SetBool("Land", true); UIManager.Instance.CompleteProgress(); SoundManager.Instance.PlaySfx(SoundManager.Instance.celebrationSfx); SoundManager.Instance.StopBGM(); UIManager.Instance.CallCompletedLevel(); fireFx.SetActive(false); GameManager.Instance.gameIsComplete = true; break; case "Ground": Debug.Log("Game Over"); anim.SetBool("Death", true); Invoke("Restart", 3f); fireFx.SetActive(false); break; } }