void ResetParams() { isBeingPopped = false; isReleased = false; flyingObjectScript = null; containedBird = false; transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); }
void CheckOverlap() { Bounds bounds = myCollider.bounds; // radius of which flying objects can be attracted float attractorRadius = myCollider.radius * transform.localScale.x + buffRadius; // radius of which flying object can be fit into this bubble // also radius of which flying object can be scared float radius = myCollider.radius * transform.localScale.x; Collider2D nearbyBird = Physics2D.OverlapCircle(bounds.center, attractorRadius, 1 << LayerMask.NameToLayer("Bird")); if (nearbyBird) { flyingObjectScript = nearbyBird.gameObject.GetComponent <FlyingObjectInterface>(); if (flyingObjectScript.IsAttractableToBubble()) { // if bird's size fit into this bubble if (nearbyBird.bounds.size.x <= 2 * radius) { flyingObjectScript.FitIntoBubble(myCollider); containedBird = true; StartCoroutine(PopBubble()); } // bubble pops and bird flies faster else { // Make sure bubble does not belong to a bird first before calling the PopBubble routine if (!containedBird) { Collider2D scaredBird = Physics2D.OverlapCircle(bounds.center, radius, 1 << LayerMask.NameToLayer("Bird")); // If a bird is lerping to the middle of this bubble, and this bubble pops to other bigger bird, this currently lerping bird // will appear to be dangling because the bubble that it belongs to has just popped to a bigger bird. if (scaredBird) { flyingObjectScript = scaredBird.gameObject.GetComponent <FlyingObjectInterface>(); // only pop to birds that are attractable to bubble if (flyingObjectScript.IsAttractableToBubble()) { StartCoroutine(PopBubble()); } } } } } } }
IEnumerator PopBubble() { // indicate that this coroutine is running, so we don't allow this bubble to catch bird when bubble // is about to pop isBeingPopped = true; if (!containedBird) { yield return(new WaitForSeconds(0.1f)); SoundManager.Instance.BubblePlayOneShot(SoundManager.Instance.bubblePopBlank); animator.SetTrigger("bubblePop"); flyingObjectScript.IncreaseVelocity(); // prevent angry state trigger from accumulating if (!BlowBubble.Instance.IsInFailState && !BlowBubble.Instance.IsInAngryState && !BlowBubble.Instance.IsInPopState) { BlowBubble.Instance.SetAnimatorTrigger("angry"); } CancelInvoke("Shrink"); Instantiate(burst, this.transform.position, Quaternion.identity); GameManager.instance.SetCoin(0); PoolManager.instance.ReturnObjectToPool(gameObject); } else { yield return(new WaitForSeconds(lifespanBeforePop)); SoundManager.Instance.BubblePlayOneShot(SoundManager.Instance.bubblePopCatch); animator.SetTrigger("bubblePop"); flyingObjectScript.SetBubbleCollider(null); flyingObjectScript = null; CancelInvoke("Shrink"); Instantiate(burst, this.transform.position, Quaternion.identity); GameManager.instance.SetCoin(1); PoolManager.instance.ReturnObjectToPool(gameObject); } }