Beispiel #1
0
    // changes the energy from the player
    // also notifies the UI (if present)
    public void ModifyHealth(int amount)
    {
        //avoid going over the maximum health by forcin
        if (health + amount > maxHealth)
        {
            amount = maxHealth - health;
        }

        health += amount;

        // Notify the UI so it will change the number in the corner
        if (userInterface != null &&
            playerNumber != -1)
        {
            userInterface.ChangeHealth(amount, playerNumber);
        }

        //
        if (amount < 0)
        {
            if (GetComponent <SpriteRenderer>() != null)
            {
                GetComponent <SpriteRenderer>().color = hitColor;
                Invoke("BackToColor", 0.1f);
            }
        }

        //DEAD
        if (health <= 0)
        {
            // AGREGAR ALGO ANTES DE MORIR
            userInterface.AddPoints(0, score);
            Destroy(gameObject);
        }
    }
Beispiel #2
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("Water"))
        {
            if (userInterface != null)
            {
                // add one point
                WaterAttribute b = collisionData.gameObject.GetComponent <WaterAttribute>();
                if (b != null)
                {
                    userInterface.AddPoints(b.playerId, pointsWorth);
                }
                else
                {
                    Debug.Log("Use a WaterAttribute 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);
        }
    }
Beispiel #3
0
    // This function gets called everytime this object collides with another
    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        string playerTag = otherCollider.transform.root.gameObject.tag;

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

            if (audiosource != null)
            {
                audiosource.Play();
            }

            // Disable collider and rendering while the sound finishes playing
            srenderer.enabled = false;
            collider.enabled  = false;

            // Schedule this object to be destroyed
            Destroy(gameObject, 1f);
        }
    }
Beispiel #4
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);
        }
    }
Beispiel #5
0
 public override bool ExecuteAction(GameObject dataObject)
 {
     if (!_pointSet)
     {
         _pointSet = true;
         if (userInterface == null)
         {
             userInterface = GameObject.FindObjectOfType <UIScript>();
         }
         if (userInterface != null)
         {
             // add one point
             int playerId = 0;
             userInterface.AddPoints(playerId, pointsWorth);
         }
     }
     return(true); //always returns true
 }
Beispiel #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Pickup")
        {
            if (userInterface != null)
            {
                // add one point
                userInterface.AddPoints(0, 1);
            }
            _anim.SetTrigger("Happy");


            if (_audio != null)
            {
                _audio.Play();
            }
            // then destroy this object
            Destroy(collision.gameObject);
        }
    }
    // 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
            pointEffect.transform.position = this.transform.position;
            pointEffect = Instantiate(pointEffect);
            pointEffect.Play();

            Destroy(gameObject);
        }
    }