Example #1
0
    // Muda sprite e valores das armas de acordo do ID informado
    public void ChangeWeapon(int id)
    {
        gameControllerRevisao.weaponID = id;

        switch (gameControllerRevisao.weaponClassID[id])
        {
        // Espadas, Machados, Martelos
        case 0:
        {
            // Atualiza sprites
            weapons[0].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite1[id];
            weapons[1].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite2[id];
            weapons[2].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite3[id];

            // Atualiza dados
            for (int i = 0; i < weapons.Length; i++)
            {
                ArmaInfoRevisao armaInfoRevisao = weapons[i].GetComponent <ArmaInfoRevisao>();
                armaInfoRevisao.MinDamage  = gameControllerRevisao.minDamages[id];
                armaInfoRevisao.MaxDamage  = gameControllerRevisao.maxDamages[id];
                armaInfoRevisao.DamageType = gameControllerRevisao.damageTypesInt[id];
            }

            break;
        }

        // Arco
        case 1:
        {
            // Atualiza sprites
            bows[0].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite1[id];
            bows[1].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite2[id];
            bows[2].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite3[id];
            break;
        }

        // Staff
        case 2:
        {
            // Atualiza sprites
            staffs[0].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite1[id];
            staffs[1].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite2[id];
            staffs[2].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite3[id];
            staffs[3].GetComponent <SpriteRenderer>().sprite = gameControllerRevisao.weaponsSprite4[id];
            break;
        }
        }

        gameControllerRevisao.actualWeaponID = weaponID;
    }
Example #2
0
    // Quando colide com algo
    private void OnTriggerEnter2D(Collider2D other)
    {
        // Cancela o resto do script
        if (hasDied)
        {
            return;
        }

        switch (other.gameObject.tag)
        {
        case "Arma":
        {
            if (!wasHit)
            {
                wasHit = true;
                lifebarHolder.SetActive(true);
                animator.SetTrigger("hit");
                audioControllerRevisao.PlayFX(audioControllerRevisao.fxHit, 1f);

                // Propriedades da arma e calculo de dano
                ArmaInfoRevisao armaInfoRevisao = other.gameObject.GetComponent <ArmaInfoRevisao> ();
                float           damage          = Random.Range(armaInfoRevisao.MinDamage, armaInfoRevisao.MaxDamage);
                int             damageType      = armaInfoRevisao.DamageType;
                float           inflictedDamage = damage + (damage * (damageTypeValues[damageType] / 100));
                maxLife -= Mathf.RoundToInt(inflictedDamage);

                // Define percentual e barra
                lifePercentual = (float)actualLife / (float)maxLife;
                lifePercentual = (lifePercentual < 0 ? 0 : lifePercentual);
                lifebarTransform.localScale = new Vector3(lifePercentual, 1, 1);

                if (maxLife <= 0)
                {
                    hasDied = true;
                    animator.SetInteger("id_animation", 3);
                    StartCoroutine("SpawnLoot");
                }
                else
                {
                    // Instancia efeito de dano
                    GameObject effectTemp = Instantiate(gameControllerRevisao.damageEffect[damageType], this.transform.position, this.transform.rotation);
                    Destroy(effectTemp, 1f);

                    // Instancia Text com Dano e define propriedades
                    GameObject damageTemp = Instantiate(damageTextPrefab, this.transform.position, this.transform.rotation) as GameObject;
                    damageTemp.GetComponent <MeshRenderer> ().sortingLayerName = "HUD";
                    damageTemp.GetComponent <TextMeshPro> ().text = Mathf.RoundToInt(inflictedDamage).ToString();
                    float xForce = 50;
                    xForce *= (!playerIsLookingLeft ? -1 : 1);
                    damageTemp.GetComponent <Rigidbody2D>().AddForce(new Vector2(xForce, 200));
                    Destroy(damageTemp, 1f);

                    // Inicia animacao e efeito de Knockback
                    GameObject knockbackTemp = Instantiate(knockforcePrefab, knockforceTransform.position, knockforceTransform.rotation) as GameObject;
                    Destroy(knockbackTemp, 0.02f);
                    StartCoroutine("Invulnerable");
                }
            }

            break;
        }

        default:
        {
            break;
        }
        }
    }