Beispiel #1
0
    void Update()
    {
        spellTimer -= Time.deltaTime;

        if (spellTimer <= 0)
        {
            audioManager.iceHitAudio();
            Instantiate(explosionPrefab, transform.position, explosionPrefab.transform.rotation);
            Destroy(gameObject);
        }

        Vector2 target = playerCtrl.gameObject.transform.position;

        target.y += 0.3f;
        target.x -= 0.1f;
        float step = speed * Time.deltaTime;

        // move sprite towards the target location
        transform.position = Vector2.MoveTowards(transform.position, target, step);
    }
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Ability")
        {
            return;
        }

        switch (damageType)
        {
        case 1:
            audioManager.fireHitAudio();
            break;

        case 2:
            audioManager.poisonHitAudio();
            break;

        case 3:
            audioManager.iceHitAudio();
            break;

        case 4:
            audioManager.voidHitAudio();
            break;
        }

        if (collision.gameObject.tag == "Enemy")
        {
            collision.gameObject.GetComponent <EnemyHealth>().TakeDamage(Random.Range(damageLowerBound, damageUpperBound), travelingLeft, true, damageType);
            Instantiate(explosionPrefab, new Vector3(collision.contacts[0].point.x, collision.contacts[0].point.y, 0), Quaternion.identity);

            enemyState = collision.gameObject.GetComponent <EnemyState>();
            if (enemyState.isEffected == true)
            {
                Destroy(gameObject);
            }
            else
            {
                GameObject specialEffect = Instantiate(effect) as GameObject;
                Effect     effectInfo    = specialEffect.GetComponentInChildren <Effect>();

                effectInfo.enemy         = collision.gameObject.GetComponent <EnemyHealth>();
                effectInfo.enemyState    = enemyState;
                effectInfo.stats         = stats;
                effectInfo.travelingLeft = travelingLeft;
                Destroy(gameObject);
            }
        }
        else if (collision.gameObject.tag != "FX" && collision.gameObject.tag != "Enemy")
        {
            Instantiate(explosionPrefab, new Vector3(collision.contacts[0].point.x, collision.contacts[0].point.y, 0), Quaternion.identity);
            Destroy(gameObject);
        }
    }