/*---------------------------------------------------------------------------------------------- * Name: OnCollisionEnter2D * Type: Method * Purpose: Handles collisions with other physics objects. * Input: Collision2D colInfo, contains the collision information for this collision. * Output: Nothing. * ----------------------------------------------------------------------------------------------*/ void OnCollisionEnter2D(Collision2D colInfo) { // Determine what this object has collided with via tag. switch (colInfo.collider.tag) { case Constants.PlayerTag: // Play contact sound. sound.Play(); // Determine if this object should respawn or not. if (respawn) { Respawn(); } else { gameObject.SetActive(false); } // Check if this object is a friend. if (friend) { // This object is a friend. Add points, add a friend pickup, and add health. master.AddPoints(scoreValue); master.FriendPickup(); player.AddHealth(healthValue); } else { // This object is not a friend. Reduce points and health accordingly. master.AddPoints(-scoreValue); player.AddHealth(-healthValue); } break; case Constants.GroundTag: // Determine if this object should respawn or not. if (respawn) { Respawn(); } else { gameObject.SetActive(false); } break; case Constants.BulletTag: // Check if this object is a friend. if (!friend) { // Play contact sound. sound.Play(); // Determine if this object should respawn or not. if (respawn) { Respawn(); } else { gameObject.SetActive(false); } // Add points. master.AddPoints(scoreValue); } break; } }