Example #1
0
    private void OnTriggerEnter2D(Collider2D colliderData)
    {
        // ORIGINAL
        HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);

            if (destroyWhenActivated)
            {
                Destroy(this.gameObject);
            }
        }

        // PROFE
        HealthSystemProfe healthScriptProfe = colliderData.gameObject.GetComponent <HealthSystemProfe>();

        if (healthScriptProfe != null)
        {
            // subtract health from the player
            healthScriptProfe.ModifyHealth(healthChange);

            if (destroyWhenActivated)
            {
                Destroy(this.gameObject);
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider != killcollider)
        {
            // This isn't the player, but we still may want to destroy the
            // object anyway (e.g., goomba falling in a pit).
            if (destroyWhenActivated)
            {
                Destroy(collider.gameObject);
            }
            return;
        }

        GameObject playerGameObject = GameObject.FindWithTag("Player");
        // This is a modification from the original script which obtained the
        // HealthSystemAttribute from the colliding object.  Since our game
        // has three colliders (head, body, feet), this won't work.  We require
        // the "player" to have the HealthSystemAttribute.

        HealthSystemAttribute healthScript = playerGameObject.GetComponent <HealthSystemAttribute>();

        //HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent<HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);

            if (destroyWhenActivated)
            {
                Destroy(playerGameObject);
            }
        }
    }
    // WARNING: take if from the Project panel, NOT the Scene/Hierarchy!
    // Creates a new GameObject

    private void OnTriggerEnter2D()
    {
        HealthSystemAttribute healthScript = gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript.health <= 0)
        {
            Create();
        }
    }
Example #4
0
    public void DestroyHealth()
    {
        HealthSystemAttribute healthScript = tuhottava.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);
        }
    }
    private void OnTriggerEnter2D(Collider2D colliderData)
    {
        HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);
        }
    }
    // public string otherPlayerTag;


    // This function gets called everytime this object collides with another
    private void OnCollisionEnter2D(Collision2D collisionData)
    {
        HealthSystemAttribute healthScript = collisionData.gameObject.GetComponent <HealthSystemAttribute>();
        string tag = collisionData.gameObject.tag;

        if (healthScript != null && gameObject.tag != tag)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);
        }
    }
Example #7
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        HealthSystemAttribute healthScript = collision.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            if (healthScript.ModifyHealth(healthChange))
            {
                GetComponent <AudioSource>().Play();
            }
        }
    }
Example #8
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;


                HealthSystemAttribute player = otherCollider.GetComponent <HealthSystemAttribute>();
                //Could carry more slime
                if (player)
                {
                    userInterface.AddScore(playerId, player.SaveCount);
                    player.SaveCount = 0;
                    player.GetComponent <Move>().ChangeSpeedAndScale(0);
                    HealthSystemAttribute Hp = player.GetComponent <HealthSystemAttribute>();
                    if (Hp != null)
                    {
                        //Cure Audio Effect
                        if (Hp.health < Hp.MaxHealth)
                        {
                            Hp.health += 1;
                            if (Hp.health < Hp.MaxHealth)
                            {
                                audio.clip = AddHp;
                            }
                            else
                            {
                                audio.clip = AddHpFull;
                            }

                            audio.Play();
                            //Update amount of hp on ui
                            if (ui)
                            {
                                ui.SetHealth(Hp.health, Hp.GetplayerNumber());
                            }
                        }
                    }
                }
            }
        }
    }
    private void OnTriggerStay2D(Collider2D otherCollider)
    {
        HealthSystemAttribute healthScript = otherCollider.gameObject.GetComponent <HealthSystemAttribute>();

        if (Time.time >= lastTimeTriggerStayCalled + frequency && healthScript == true) //check also the frequency
        {
            //check for the tag of the object which entered the area, if necessary
            if (otherCollider.CompareTag("Player"))
            {
                // increment time
                lastTimeTriggerStayCalled = Time.time;
                // subtract health from the player
                healthScript.ModifyHealth(healthChange);
            }
        }
    }
Example #10
0
    // This function gets called everytime this object collides with another
    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        if (hasBeenSave)
        {
            return;
        }

        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;


                HealthSystemAttribute player = otherCollider.GetComponent <HealthSystemAttribute>();
                //Could carry more slime
                if (player && !player.IsMaxSave())
                {
                    hasBeenSave = true;
                    player.SaveOneInjureSlime();
                    player.GetComponent <Move>().ChangeSpeedAndScale(player.SaveCount);

                    //Play Audio
                    if (audio)
                    {
                        if (player.SaveCount >= 3)
                        {
                            audio.clip = SaveFullClip;
                        }
                        else
                        {
                            audio.clip = SaveAucioClip;
                        }

                        audio.Play();
                    }
                    GetComponent <SpriteRenderer>().color = new Color(0, 0, 0, 0);

                    Destroy(gameObject, 3);
                }
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D colliderData)
    {
        if (gameObject.tag == "Enemy" && colliderData.tag != "EnemyBullet")
        {
            HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();
            if (healthScript != null)
            {
                // subtract health from the player
                healthScript.ModifyHealth(healthChange);

                if (destroyWhenActivated)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Example #12
0
    private void OnTriggerEnter2D(Collider2D colliderData)
    {
        HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);


            if (destroyWhenActivated)
            {
                Destroy(this.gameObject);
            }
        }
        //Debug.Log("AddD" + healthChange);
    }
    public void OnTriggerChildEnter2D(Collider2D colliderData, Vector2 position)
    {
        HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);
        }

        Rigidbody2D rb = colliderData.gameObject.GetComponent <Rigidbody2D>();

        if (rb != null)
        {
            rb.AddForce(direction * force, ForceMode2D.Impulse);
        }
    }
Example #14
0
    private void OnTriggerEnter2D(Collider2D colliderData)
    {
        if (colliderData.CompareTag(filterTag) || !filterByTag)
        {
            HealthSystemAttribute healthScript = colliderData.gameObject.GetComponent <HealthSystemAttribute>();
            if (healthScript != null)
            {
                // subtract health from the player
                healthScript.ModifyHealth(healthChange);

                if (destroyWhenActivated)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }
Example #15
0
    public void SetupUnitData()
    {
        // Reference Playground HealthSystemAttribute component
        HealthSystemAttribute healthSystem = GetComponent <HealthSystemAttribute>();

        if (healthSystem)
        {
            healthSystem.maxHealth = (int)unitData.maxHealth;
            healthSystem.health    = (int)unitData.health;
        }

        ModifyHealthAttribute modifyHealthAttrb = GetComponent <ModifyHealthAttribute>();

        if (modifyHealthAttrb)
        {
            modifyHealthAttrb.healthChange = (int)-unitData.collisionDamage;
        }
    }
Example #16
0
    // This function gets called everytime this object collides with another
    private void OnCollisionEnter2D(Collision2D collisionData)
    {
        HealthSystemAttribute healthScript = collisionData.gameObject.GetComponent <HealthSystemAttribute>();

        if (healthScript != null)
        {
            // subtract health from the player
            healthScript.ModifyHealth(healthChange);

            if (knockback)
            {
                Rigidbody2D rigidbody = collisionData.gameObject.GetComponent <Rigidbody2D>();
                if (rigidbody)
                {
                    rigidbody.AddForce(-collisionData.relativeVelocity.normalized * knockbackStrength, ForceMode2D.Impulse);
                }
            }
        }
    }