Exemplo n.º 1
0
    public void ItemDrop(Ennemis perso)
    {
        float result = UnityEngine.Random.Range(1, 100);

        if (result / 100 > 0.5f)
        {
            result = UnityEngine.Random.Range(1, 100);
            if (result / 100 > 0.5f)          //1-50: Missile, 51-100: Health
            {
                PlayerCharacter2D pc = FindObjectOfType <PlayerCharacter2D>();
                if (pc.HasUpgrade("Missile"))
                {
                    GameObject clone = Instantiate(itemPickupPrefab, perso.transform.position, perso.transform.rotation);
                    clone.GetComponent <PickupItem>().PickupType = "Missile";
                    clone.GetComponent <Animator>().Play("Missile");
                    clone.GetComponent <PickupItem>().Valeur = 5;
                    //Debug.Log("missile drop");
                }
            }
            else
            {
                //Debug.Log("health drop");
                GameObject clone = Instantiate(itemPickupPrefab, perso.transform.position, perso.transform.rotation);
                clone.GetComponent <PickupItem>().PickupType = "Health";
                clone.GetComponent <Animator>().Play("Health");
                clone.GetComponent <PickupItem>().Valeur = 10;
            }
        }
    }
Exemplo n.º 2
0
    void Pickup(Collider2D player)
    {
        //fait de quoi sur le player
        GameObject        monjoueur = GameObject.FindGameObjectWithTag("Player");
        PlayerCharacter2D pc        = (PlayerCharacter2D)monjoueur.GetComponent(typeof(PlayerCharacter2D));

        if (pc == null)
        {
            Debug.Log("Player not found");
            return;
        }

        if (pc.upgrading)
        {
            return;
        }
        else
        {
            pc.upgrading = true;
        }

        //pc.ToggleUpgrade(UpgradeName);

        if (!pc.HasUpgrade(UpgradeName) || (UpgradeName == "Missile" && pc.HasUpgrade("Missile")))
        {
            switch (UpgradeName)
            {
            case "MorphBall":
                pc.ToggleUpgrade(UpgradeName);
                pc.gameObject.AddComponent(typeof(MorphBall));
                break;

            case "MorphBomb":
                pc.ToggleUpgrade(UpgradeName);
                break;

            case "GrappleBeam":
                pc.ToggleUpgrade(UpgradeName);
                pc.AddWeapon("GrappleBeam");
                pc.gameObject.GetComponent <GrappleBeam>().enabled = true;
                pc.gameObject.GetComponent <GrappleBeam>().UpdateGUI(false);
                break;

            case "Missile":
                pc.joueurStats.nbMissileMax += 5;
                pc.joueurStats.nbMissile     = pc.joueurStats.nbMissileMax;
                if (pc.HasUpgrade("Missile"))
                {
                    pc.UpdateMissileUI();
                }
                else
                {
                    pc.ToggleUpgrade(UpgradeName);
                    pc.AddWeapon("Missile");
                }
                Debug.Log("missile max 1: " + pc.joueurStats.nbMissileMax);
                break;

            case "MissileExpansion":
                pc.joueurStats.nbMissileMax += 5;
                pc.joueurStats.nbMissile     = pc.joueurStats.nbMissileMax;
                pc.UpdateMissileUI();
                break;

            case "HealthExpansion":
                pc.joueurStats.vieMax += 100;
                pc.joueurStats.vie     = pc.joueurStats.vieMax;
                pc.UpdateHealthBar();
                break;

            default:
                Debug.Log("Upgrade non spécifiée ou non reconnue");
                pc.gameObject.AddComponent(typeof(TestUpgradeBehavior));
                break;
            }

            gameObject.GetComponent <Animator>().Play("Disapear");
        }

        GetComponent <DialogueTrigger>().TriggerDialogue();

        Destroy(gameObject, 0.25f);
    }