// 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.AddOnePoint(playerId);
            }

            // then destroy this object
            gameObject.GetComponent <Collider2D>().enabled = false;

            GameObject.FindGameObjectsWithTag("gate")[0].GetComponent <Collider2D>().enabled      = false;
            GameObject.FindGameObjectsWithTag("gate")[0].GetComponent <Renderer>().material.color = Color.red;
        }
    }
Beispiel #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.AddOnePoint(playerId);
            }

            // then destroy this object
            Destroy(gameObject);
        }
    }
Beispiel #3
0
    // This function gets called everytime this object collides with another
    private void OnCollisionEnter2D(Collision2D 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.AddOnePoint(b.playerId);
                }
            }

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