Example #1
0
        public void Initialize(Mecha mecha)
        {
            if (mecha == null)
            {
                Clean();
            }
            else
            {
                if (targetMecha != mecha)
                {
                    Clean();
                    SliderContainer.gameObject.SetActive(true);
                    targetMecha = mecha;
                    LifeSlider  = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.HUDSlider].AllocateGameObject <HUDSlider>(SliderContainer);
                    LifeSlider.Initialize(2, LifeSliderColor, out mecha.MechaInfo.OnLifeChange);
                    //PowerSlider = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.HUDSlider].AllocateGameObject<HUDSlider>(SliderContainer);
                    //PowerSlider.Initialize(2, PowerSliderColor, out mecha.MechaInfo.OnInputPowerChange);

                    MechaNameText.text = mecha.MechaInfo.MechaName;

                    LifeSlider.SetValue(mecha.MechaInfo.M_LeftLife, mecha.MechaInfo.M_TotalLife);
                    //PowerSlider.SetValue(mecha.MechaInfo.M_LeftPower, mecha.MechaInfo.M_TotalPower);

                    targetMecha.MechaInfo.RefreshHUDPanelCoreLifeSliderCount = RefreshCoreLifeSliders;
                    targetMecha.MechaInfo.RefreshHUDPanelCoreLifeSliderCount();
                }
            }
        }
    public void OnTriggerEnter(Collider other)
    {
        if (vies <= 0)
        {
            return;
        }

        // Réagit aux collisions non physique
        if (other.gameObject.tag == "Coin")
        {
            // Désactiver les multiples points
            other.GetComponent <BoxCollider>().enabled      = false;
            other.GetComponentInChildren <Light> ().enabled = false;

            // Joue le système de particules
            other.GetComponentInChildren <ParticleSystem> ().Play();

            coinGagne.Play();

            // Cache le cube
            other.GetComponent <MeshRenderer> ().enabled = false;

            // Détruit l'objet après une seconde pour laisser l'animation jouer
            Destroy(other.gameObject, 1.0f);

            // Incrémentation du score
            if (powerUpActivatedMoney)
            {
                score = score + 2;
                progressBar.slider.value = progressBar.slider.value + 2;
            }
            else
            {
                score++;
                progressBar.slider.value++;
            }

            texteScore.text = "Coins : " + score;
        }

        if (other.gameObject.tag == "Bullet" && !powerUpActivatedInvincible)
        {
            if (shieldQuantity == 0)
            {
                // Si le joueur est touché, on décrémente sa vie
                vies--;
                lifeSlider.SetValue((float)vies / 3);

                // Joue le système de particules
                //GetComponentInChildren<ParticleSystem> ().Play ();
                GameObject blood = (GameObject)Instantiate(bloodSplatter, transform.position, transform.rotation);
                Destroy(blood, 0.5f);

                // Joue le son
                AudioSource.PlayClipAtPoint(catCollision, transform.position);

                // Détruit l'objet
                Destroy(other.gameObject);

                // quand le joueur a été touché 3 fois
                if (vies == 0)
                {
                    // Contradiction avec le fait que le joueur meurt
                    //gameObject.transform.position = Vector3.zero;
                    //vies = 3

                    // reset du score et de la vie
                    score = 0;

                    // Animation de mort
                    animator.SetTrigger("Die");

                    // Affichage du game over!
                    texteMort.enabled = true;
                    Invoke("CacherText", 3.0f);
                }
            }
            else
            {
                shieldQuantity--;
                texteShieldQuantity.text = "" + shieldQuantity;
            }

            texteVies.text  = "Life : " + vies;
            texteScore.text = "Coins : " + score;
        }

        // Power-up : ExtraLife permet de gagner une vie supplémentaire
        if (other.gameObject.tag == "ExtraLife")
        {
            AudioSource.PlayClipAtPoint(powerUp, other.transform.position);

            // Cache le power-up
            other.GetComponentInChildren <Light> ().enabled = false;
            Destroy(other.gameObject);

            if (vies < 3)               //3 vies max
            {
                vies++;
                textePowerUp.GetComponent <Text> ().text = "1 Up!";
            }
            else
            {
                textePowerUp.GetComponent <Text> ().text = "Max Life!";
            }

            texteVies.text = "Life : " + vies;
            lifeSlider.SetValue((float)vies / 3);

            textePowerUpActivated = true;
        }

        // Power-up : StopCanon permet d'arrêter le tir des canons
        if (other.gameObject.tag == "StopCanon")
        {
            AudioSource.PlayClipAtPoint(powerUp, other.transform.position);

            // Cache le power-up
            other.GetComponentInChildren <Light> ().enabled = false;
            Destroy(other.gameObject);

            // Arrête les canons
            foreach (GameObject canon in canons)
            {
                canon.GetComponent <Cannon> ().StopAllCoroutines();
            }

            powerUpActivatedStopCanon = true;

            // Cooldown
            stopCanonTimeRemaining = 5.0f;
            stopCanonActivatedIcon.GetComponent <Image>().fillAmount = 1.0f;

            textePowerUp.GetComponent <Text>().text = "Freeze! Let It Go ~";
            textePowerUpActivated = true;
        }

        // Power-up : Invincible ignore les collision avec les chats
        if (other.gameObject.tag == "Invincible")
        {
            AudioSource.PlayClipAtPoint(powerUp, other.transform.position);

            // Cache le power-up
            other.GetComponentInChildren <Light> ().enabled = false;
            Destroy(other.gameObject);

            powerUpActivatedInvincible = true;

            // Cooldown
            invincibleTimeRemaining = 5.0f;
            invincibleActivatedIcon.GetComponent <Image>().fillAmount = 1.0f;

            textePowerUp.GetComponent <Text>().text = "God Mode!";
            textePowerUpActivated = true;
        }

        // Power-up : Money double les points obtenus avec un Coin
        if (other.gameObject.tag == "Money")
        {
            AudioSource.PlayClipAtPoint(powerUp, other.transform.position);

            // Cache le power-up
            other.GetComponentInChildren <Light> ().enabled = false;
            Destroy(other.gameObject);

            powerUpActivatedMoney = true;

            // Cooldown
            moneyTimeRemaining = 5.0f;
            moneyActivatedIcon.GetComponent <Image>().fillAmount = 1.0f;

            textePowerUp.GetComponent <Text>().text = "Bling Bling $$$";
            textePowerUpActivated = true;
        }
    }