Ejemplo n.º 1
0
        // This function gets called everytime this object collides with another trigger
        private void OnTriggerEnter2D(Collider2D collisionData)
        {
            // is the other object a Bullet?
            if (collisionData.gameObject.CompareTag("Bullet"))
            {
                if (userInterface != null)
                {
                    // add one point
                    BulletAttribute b = collisionData.gameObject.GetComponent <BulletAttribute>();
                    if (b != null)
                    {
                        userInterface.AddPoints(b.playerId, pointsWorth);
                    }
                    else
                    {
                        Debug.Log("Use a BulletAttribute on one of the objects involved in the collision if you want one of the players to receive points for destroying the target.");
                    }
                }
                else
                {
                    Debug.Log("There is no UI in the scene, hence points can't be displayed.");
                }

                // then destroy this object
                Destroy(gameObject);
            }
        }
Ejemplo n.º 2
0
        // This function gets called everytime this object collides with another
        private void OnTriggerEnter2D(Collider2D otherCollider)
        {
            string playerTag = otherCollider.gameObject.tag;

            // is the other object a player?
            if (playerTag == "Player" || playerTag == "Player2")
            {
                if (userInterface != null)
                {
                    // add one point
                    int playerId = (playerTag == "Player") ? 0 : 1;
                    userInterface.AddPoints(playerId, pointsWorth);
                }

                // then destroy this object
                Destroy(gameObject);
            }
        }