Пример #1
0
    void createAnotherButterfly()
    {
        #region start the countdown until the PC is respawned
        //start countdown until a new PCButterfly is made set health to 1000
        if (timeTilRespawnActive)
        {
            //set the new butterflies health to 1000
            scoreHealthLivesCounter.alterHealth(1000);

            //countdown
            timeTilRespawn = (timeTilRespawn - (1 * Time.deltaTime));

            #region when timer runs out, recreate a PC

            //when timer runs out, create a new PC and create a new text
            if (timeTilRespawn <= 0)
            {
                //remove all bullets
                bulletManager.destroyAllEnemyBullets();

                //timer set back to one
                timeTilRespawn = 1;

                //timer is no longer counting down
                timeTilRespawnActive = false;

                //lower life count in this script
                lives = lives - 1;

                //instantiate a new gameObejct prefab
                GameObject PC;
                PC = Instantiate(newButterfly, startPoint, Quaternion.identity) as GameObject;

                //now that the butterflyPC has come back, it's time to re-initialize it
                butterflyPC = GameObject.FindWithTag("Player");

                #region set PCisDestroyed back to false if there is a butterflyPC

                //if there is a butterflyPC
                if (butterflyPC)
                {
                    //set PCisDestroyed back to false so that reduceLife can be called the next time the PC disappears
                    PCisDestroyed = false;
                }
                #endregion
            }
            #endregion
        }
        #endregion
    }
Пример #2
0
    // On trigger function
    void OnTriggerEnter2D(Collider2D col)
    {
        #region get beam reference

        //create a variable of type DamageThePlayerButterfly called beam, this represents the collided object (which will be the beams the enemy butterfly shoots)
        DamageThePlayerButterfly beam = col.gameObject.GetComponent <DamageThePlayerButterfly>();

        #endregion get beam reference

//        if(col.tag == "Enemy")
//        {
//            PCHealth = 0;
//            print("don'tTouchMEEEE");
//        }

        #region if the beam exists...

        if (beam)
        {
            #region reduce health and destroy beam
            //reduce health by the amount specified in GetDamage
            PCHealth -= beam.GetDamage();

            //pass the new health value to the ScoreHealthLivesCounter
            scorehealthlivescounter.alterHealth(PCHealth);

            //destroy beam
            beam.Hit();

            #endregion

            #region if health is below zero...
            //out of health?
            if (PCHealth <= 0)
            {
                #region play sound and die
                //play sound
                AudioSource.PlayClipAtPoint(poof, transform.position);

                //die
                Destroy(gameObject);

                #endregion
            }

            #endregion
        }

        #endregion
    }