/// <summary> /// Destroys ball when it becomes invisible /// </summary> protected void OnBecameInvisible() { //// death timer destruction is in Update //if (!deathTimer.Finished) //{ // only lost ball if outside screen if (OutsideScreen()) { // adjust score in HUD if (transform.position.x > 0) { pointsAddedEvent.Invoke(ScreenSide.Left, points); } else { pointsAddedEvent.Invoke(ScreenSide.Right, points); } // spawn a new ball and destroy self //Camera.main.GetComponent<BallSpawner>().SpawnBall(); Destroy(gameObject); } else { // spawn a new ball and destroy self //Camera.main.GetComponent<BallSpawner>().SpawnBall(); pointsAddedEvent.Invoke(ScreenSide.None, points); Destroy(gameObject); } //} }
/// <summary> /// Checks whether or not to eat a teddy bear /// </summary> /// <param name="coll">collision info</param> void OnCollisionEnter2D(Collision2D coll) { // move head bounding box to correct location headBoundingBoxLocation.y = fishCollider.transform.position.y; if (spriteRenderer.sprite == leftFacingSprite) { headBoundingBoxLocation.x = fishCollider.transform.position.x - headBoundingBoxXOfsset; } else { headBoundingBoxLocation.x = fishCollider.transform.position.x + headBoundingBoxXOfsset; } headBoundingBox.center = headBoundingBoxLocation; // destroy teddy bear if it collides with head bounding box if (coll.collider.bounds.Intersects(headBoundingBox)) { Destroy(coll.gameObject); // update score pointsAddedEvent.Invoke(bearPoints); } }
virtual protected void OnCollisionEnter2D(Collision2D col) { //hud.Score (points); pointAddedEvent.Invoke(points); blockDestroyedEvent.Invoke(); Destroy(gameObject); }
/// <summary> /// Destroys ball if it leaves playing field (Use clamps to keep in playing field) /// </summary> void OnBecameInvisible() { Vector2 position = transform.position; if (!timer.Finished && position.x < ScreenUtils.ScreenLeft) { //For the points screen left //GameObject.FindGameObjectWithTag ("HUD").GetComponent<HUD>().AddScore(ScreenSide.Right, points); pointsAddedEvent.Invoke(ScreenSide.Right, points); //New event method SpawnAndDestroy(); } else if (!timer.Finished && position.x > ScreenUtils.ScreenRight) { //For the points screen right //GameObject.FindGameObjectWithTag("HUD").GetComponent<HUD>().AddScore(ScreenSide.Left, points); pointsAddedEvent.Invoke(ScreenSide.Left, points); //New event method SpawnAndDestroy(); } }
protected virtual void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.CompareTag("Ball")) { SoundManager.instance.AudSource.PlayOneShot(SoundManager.instance.StandardBlockHit); Destroy(this.gameObject); blockDestroyedEvent.Invoke(0); pointsAddedEvent.Invoke(standardPoints); } }
virtual protected void OnCollisionEnter2D(Collision2D collision) { LevelBuilder.numOfBlocks--; if (LevelBuilder.numOfBlocks == 0) { lastBlockDestroyed.Invoke(); } AudioManager.Play(AudioClipName.BlockDestroy); Destroy(gameObject); pointsAddedEvent.Invoke(blockValue); }
virtual protected void OnCollisionEnter2D() { if (gameObject.CompareTag("StandardBlock")) { pointsAddedEvent.Invoke((int)standardBlockPoints); AudioManager.Play(AudioClipName.Standard); } else if (gameObject.CompareTag("BonusBlock")) { AudioManager.Play(AudioClipName.Bonus); pointsAddedEvent.Invoke((int)bonusBlockPoints); } else if (gameObject.CompareTag("PickUpBlock")) { pointsAddedEvent.Invoke((int)pickUpBlockPoints); } Destroy(gameObject); blockDestroyEvent.Invoke(); }
/// <summary> /// Sent when an incoming collider makes contact with this object's /// collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> virtual protected void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("Ball")) { pointsAddedEvent.Invoke(points); if (GameObject.FindGameObjectsWithTag("Block").Length == 1) { blockDestroyedEvent.Invoke(); AudioManager.Play(AudioClipName.YouWin); } Destroy(gameObject); } }
/// <summary> /// Destroys ball when offscreen /// </summary> private void OnBecameInvisible() { // Regulates scoring if (transform.position.x + ballHalfWidth < ScreenUtils.ScreenLeft || transform.position.x + ballHalfWidth > ScreenUtils.ScreenRight) { // Checks for screen side to apply appropriate scoring // Ball goes off Right --- Scores + for Left if (transform.position.x > 0) { pointsAddedEvent.Invoke(ScreenSide.Left, score); ballLostEvent.Invoke(); deathTimer.Stop(); } // Ball goes off Left --- Score + for Right else if (transform.position.x < 0) { pointsAddedEvent.Invoke(ScreenSide.Right, score); ballLostEvent.Invoke(); deathTimer.Stop(); } Destroy(gameObject); } }
/// <summary> /// Destroys the block on collision with a ball /// </summary> /// <param name="coll">Coll.</param> virtual protected void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.CompareTag("Ball")) { // HUD.AddPoints(points); pointsAddedEvent.Invoke(points); GameObject[] blocks = GameObject.FindGameObjectsWithTag("Block"); if (blocks.Length == 1) { blockDestroyedEvent.Invoke(); } //AudioManager.Play(AudioClipName.BlockHit); Destroy(gameObject); } }
/// <summary> /// When a collision happens with a ball, add points and destroy this block /// </summary> /// <param name="col"></param> virtual protected void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.CompareTag("Ball")) { //Add 'destroyPoints' from global points pointsAddedEvent.Invoke((int)destroyPoints); //Invoke reduce number of blcoks reduceBlocksLeftEvent.Invoke(); //play audio AudioManager.Play(AudioClipName.BallCollision); //Destroy this block Destroy(gameObject); } }
private static void _onPointsAdded() => PointsAddedEvent?.Invoke(null, Points);