Beispiel #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag.Equals("Player"))
        {
            if (gameObject.tag.Equals("Health"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.increaseHealth(100);

                Destroy(gameObject);
            }
            else if (gameObject.tag.Equals("Oxygen"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.increaseOxygen(50);

                Destroy(gameObject);
            }
            else if (gameObject.tag.Equals("DamageObject"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.decreaseHealth(10);
            }
            else if (gameObject.tag.Equals("DecreaseOxygen"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.decreaseOxygen(5);
            }
            else
            {
                counter = 0;

                for (int i = 0; i < inventory.slots.Length; i++)
                {
                    if (!inventory.isFull[i] && counter == 0)
                    {
                        inventory.isFull[i] = true;

                        inventory.slots[i].tag = item.tag;

                        Instantiate(item, inventory.slots[i].transform, false);
                        counter++;
                        Debug.Log("Picked up item");
                        Destroy(gameObject);
                        break;
                    }
                }
            }
        }
    }
Beispiel #2
0
    void OnTriggerStay2D(Collider2D collision)
    {
        if (gameObject.tag.Equals("DamageObject"))
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.decreaseHealth(10 * Time.deltaTime);
            }
        }

        if (gameObject.tag.Equals("DecreaseOxygen"))
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                am = collision.gameObject.GetComponent <AstronautMovement>();
                am.decreaseOxygen(10 * Time.deltaTime);
            }
        }
    }