Example #1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        // If hit by a bullet, die
        if (collision.gameObject.tag == "Bullet")
        {
            if (!isDead)
            {
                healthBar.value = ((float)--hitPoints) / startingHitPoints;

                if (hitPoints <= 0)
                {
                    win.enabled = true;
                    isDead      = true;
                    bloodParticleSystem.Play();
                    enemyRigidbody2D.AddForce(collision.gameObject.transform.position * impactForce, ForceMode2D.Impulse);
                    hitSound.Play();
                    gameControllerScript.IncrementScore();
                    Destroy(gameObject, destroyDelay);
                    CancelInvoke();
                }
                else
                {
                    for (int i = 0; i < rendererComponents.Length; ++i)
                    {
                        rendererComponents[i].material.color = hitColor;
                    }
                    Invoke("RestoreColor", hitColorDuration);
                }
            }
        }
    }
 void OnTriggerEnter2D(Collider2D other)    // Tetikleyici
 {
     if (other.tag == "Star")               // Tetiklediğimiz çarpıştırıcı star tagına sahipse
     {
         myGameController.IncrementScore(); // puanı arttır
         Destroy(other.gameObject);         // yıldızı yok et
     }
 }
Example #3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     // If hit by a bullet, die
     if (collision.gameObject.tag == "Bullet")
     {
         if (!isDead)
         {
             isDead = true;
             bloodParticleSystem.Play();
             enemyRigidbody2D.AddForce(collision.gameObject.transform.position * impactForce, ForceMode2D.Impulse);
             hitSound.Play();
             gameControllerScript.IncrementScore();
             Destroy(gameObject, destroyDelay);
         }
     }
 }
Example #4
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        // If hit by a bullet, die
        if (collision.gameObject.tag == "Bullet")
        {
            if (!isDead)
            {
                if (Random.Range(0, 100) > (100 - chanceOfAmmoDrop))
                {
                    Instantiate(ammo, transform.position, new Quaternion(0, 0, 0, 0));
                }

                isDead = true;
                bloodParticleSystem.Play();
                enemyRigidbody2D.AddForce(collision.gameObject.transform.position * impactForce, ForceMode2D.Impulse);
                hitSound.Play();
                gameControllerScript.IncrementScore();

                Destroy(gameObject, destroyDelay);
            }
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "PlayerLaser")
        {
            Instantiate(LaserHit, transform.position, transform.rotation);
            Destroy(other.gameObject);

            if (Health > 0)
            {
                Health--;
            }

            if (Health <= 0)
            {
                Instantiate(Explosion, transform.position, transform.rotation);

                GameObject           gameController = GameObject.FindWithTag("GameController");
                GameControllerScript script         = gameController.GetComponent <GameControllerScript>();
                script.IncrementScore(ScoreValue);

                Destroy(gameObject);
            }
        }
    }