Exemple #1
0
    protected void OnCollisionStay2D(Collision2D collision)
    {
        if (hitTimer <= 0)
        {
            if (collision.transform.parent != null)
            {
                if (collision.transform.parent.transform.GetComponent <DefendablePoints>())
                {
                    DefendablePoints w = collision.transform.parent.transform.GetComponent <DefendablePoints>();

                    w.TakeDamage(10);

                    health  -= 15;
                    hitTimer = 0.25f;
                }
            }

            if (collision.transform.GetComponent <Player>())
            {
                pushFactor = 5;
                Player p = collision.transform.GetComponent <Player>();
                p.GetComponent <Rigidbody2D>().AddForce((p.transform.position - transform.position).normalized * pushFactor / Time.deltaTime);
                hitTimer = 0.25f;
            }
        }
    }
    //method so when this bullet hits it repairs health and buildings
    protected override void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.parent != null)
        {
            if (collision.transform.parent.transform.GetComponent <DefendablePoints>())
            {
                DefendablePoints dp = collision.transform.parent.transform.GetComponent <DefendablePoints>();

                dp.Repair(10);
            }
        }
        if (collision.transform.GetComponent <EnemyBullet>())
        {
            Destroy(gameObject);
        }
        if (collision.transform.GetComponent <DestoryBullet>())
        {
            Destroy(gameObject);
        }
        if (collision.transform.GetComponent <Wall>())
        {
            Destroy(gameObject);
        }
        if (collision.transform.GetComponent <BaseEnemy>())
        {
            BaseEnemy b = collision.transform.GetComponent <BaseEnemy>();
            b.GetComponent <Rigidbody2D>().AddForce((b.transform.position - transform.position).normalized * pushFactor / Time.deltaTime);
            Destroy(gameObject);
        }

        base.OnCollisionEnter2D(collision);
    }