private void OnTriggerEnter2D(Collider2D collision) { GameObject other = collision.gameObject; if (collision.CompareTag("Respawn")) { respawnPos = transform.position; } Star star = other.GetComponent <Star>(); if (star != null && !star.playerTouched) { star.playerTouched = true; gm.CollectStar(star); Destroy(other); StarCollectSound.Play(); int starType = (int)gm.levelStarPrefab.GetComponent <Star>().starType; if (gm.starsCollected[starType] >= portal.starsRequired) { if (Slime.activeSelf) { SlimeManager slimeManager = Slime.GetComponent <SlimeManager>(); slimeManager.DestroyBridge(); slimeManager.sprite.SetActive(false); } SlimeGuide.SetActive(true); } } Door door = other.GetComponent <Door>(); if (door != null) { gm.ShowHUDDoorStars(door); door.TryOpen(); } Portal portalCollided = other.GetComponent <Portal>(); if (portalCollided != null) { int starType = (int)gm.levelStarPrefab.GetComponent <Star>().starType; if (gm.starsCollected[starType] >= portalCollided.starsRequired) { NextLevel(); } } StarSpot starSpot = other.GetComponent <StarSpot>(); if (starSpot != null && !starSpot.touched) { starSpot.Fill(); } }
private void ActivateStarGroup() { int numRemaining = StarsRemaining(); int starsToPlace = Mathf.Min(numRemaining, STAR_GROUP_SIZE); for (int i = 0; i < starsToPlace; i++) { //activate random inactive, unfilled star int r = Random.Range(0, queuedStarSpots.Count); StarSpot spot = queuedStarSpots[r]; spot.gameObject.SetActive(true); queuedStarSpots.Remove(spot); numRemaining--; } }