Ejemplo n.º 1
0
        public void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.gameObject.CompareTag("Bullet"))
            {
                HP -= 1;
                Destroy(collision.gameObject);
                if (HP <= 0)
                {
                    AudioManager.PlaySound(AudioManager.SoundEffect.Explode);
                    gameController.AddScore(10);
                    Instantiate(explosion, transform.position, transform.rotation);
                    Destroy(gameObject);
                    EnemyDestroied();
                }
            }

            if (collision.gameObject.CompareTag("Player"))
            {
                if (collision.gameObject.GetComponent <PlayerScript>().GetHit())
                {
                    Destroy(gameObject);
                    EnemyDestroied();
                    Instantiate(explosion, transform.position, transform.rotation);
                }

                if (collision.gameObject.GetComponent <PlayerScript>().HP <= 0)
                {
                    AudioManager.PlaySound(AudioManager.SoundEffect.Explode);
                    gameController.GameOver();
                    Instantiate(explosion, collision.transform.position, collision.transform.rotation);
                    Destroy(collision.gameObject);
                }
            }
        }
Ejemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D collision)     //衝突判定
 {
     if (collision.gameObject.CompareTag("Enemy"))
     {
         gameController.AddScore(4);
         Destroy(collision.gameObject);                                          //enemyを消す
         collisioncount -= 1;
     }
 }
Ejemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.name == "Bullet(Clone)")
     {
         Debug.Log("collide with bad message");
         GameControllerScript.AddScore(10);
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 4
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Enemy"))
     {
         gameController.AddScore(10);
         //Instantiate(explosion, transform.position, transform.rotation);         //爆発の演出を出す
         Destroy(collision.gameObject);                                          //enemyを消す
         Destroy(gameObject);                                                    //B細胞を消す
     }
 }
Ejemplo n.º 5
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.layer != 10)
     {
         this.gameObject.GetComponent <AudioSource> ().Play();
         Destroy(other.gameObject);
         hp--;
         Renderer rend     = GetComponent <Renderer>();
         Color    newColor = new Color(Random.value, Random.value, Random.value, 1.0f);
         rend.material.color = newColor;
     }
     else
     {
         controller.AddScore(-100 * hp);
         controller.playSound();
         Destroy(this.gameObject);
     }
     if (hp <= 0)
     {
         controller.playSound();
         controller.AddScore(cost);
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 6
0
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Boundary"))
     {
         return;
     }
     Instantiate(explosion, transform.position, transform.rotation);
     if (other.tag == "Player")
     {
         Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
         gameController.GameOver();
     }
     gameController.AddScore(scoreValue);
     Destroy(other.gameObject);
     Destroy(gameObject);
 }
Ejemplo n.º 7
0
    void OnTriggerExit(Collider other)
    {
        /*
         *      When laser comes in contact with any GameObject this function is called.
         *      If other gameObject is player then call gameOver, else Distroy other as well as this gameObject
         */

        if (other.tag == "Player")
        {
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
            gameControllerLsr.GameOver();
        }

        Instantiate(explosion, transform.position, transform.rotation);
        gameControllerLsr.AddScore(newScoreValue: -1);
        Destroy(other.gameObject);
    }
Ejemplo n.º 8
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Bullet"))
     {
         gameController.AddScore(10);
         Instantiate(explosion, transform.position, transform.rotation);
         Destroy(collision.gameObject);
         Destroy(gameObject);
     }
     if (collision.gameObject.CompareTag("Player"))
     {
         gameController.GameOver();
         Instantiate(explosion, transform.position, transform.rotation);
         Instantiate(explosion, collision.transform.position, collision.transform.rotation);
         Destroy(collision.gameObject);
         Destroy(gameObject);
     }
 }
Ejemplo n.º 9
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     // 弾と衝突
     if (other.gameObject.CompareTag("Bullet"))
     {
         gameController.AddScore(10);  //得点を加算
         Instantiate(explosion, transform.position, transform.rotation);
         Destroy(other.gameObject);
         Destroy(gameObject);
     }
     // プレイヤーと衝突
     if (other.gameObject.CompareTag("Player"))
     {
         Instantiate(explosion, other.transform.position, other.transform.rotation);
         Destroy(other.gameObject);
         Destroy(gameObject);
     }
 }
Ejemplo n.º 10
0
 private void OnTriggerEnter2D(Collider2D collision)     //衝突判定
 {
     if (eat)
     {
         if (collision.gameObject.CompareTag("Player"))
         {
             gameController.AddScore(10);
             Destroy(gameObject);                                               //このオブジェクトを消す
             script.limit += 1;
         }
     }
     else
     {
         if (collision.gameObject.CompareTag("Enemy"))
         {
             Destroy(collision.gameObject);                                          //enemyを消す
             eat = true;
         }
     }
 }
Ejemplo n.º 11
0
    void OnTriggerExit(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Laser" || other.tag == "FireUp")           //Do nothing if the other object is of
        {                                                                                       // there tags
            return;
        }
        if (other.tag == "Player")                                                                                                              // If player then initiate GameOver
        {
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
            gameController.GameOver();
            other.gameObject.SetActive(false);
        }

        Instantiate(explosion, transform.position, transform.rotation);                                 // Show Explosion
        gameController.AddScore(newScoreValue: scoreValue);                                             // Increment Score
        if (other.tag != "Player")                                                                      //If not player then destroy both objects
        {
            Destroy(other.gameObject);
        }
        Destroy(gameObject);
    }
Ejemplo n.º 12
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary")
        {
            return;
        }
        if (other.tag == "Player")
        {
            Instantiate(playerExplosion, other.gameObject.transform.position, other.gameObject.transform.rotation);
            gameControllerScript.GameOver();
            Destroy(other.gameObject);
        }
        if (other.tag == "Bullet")
        {
            other.gameObject.SetActive(false);
        }

        Instantiate(asteroidExplosion, gameObject.transform.position, gameObject.transform.rotation);
        gameControllerScript.AddScore(scoreValue);

        gameObject.SetActive(false);
    }
Ejemplo n.º 13
0
    // この Enemy の範囲に入ってきたらという意味になる
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // もし入ってきたものが Bullet だったらと言う意味
        if (collision.gameObject.CompareTag("Bullet"))
        {
            // 10 点加算されるよう
            gameController.AddScore(10);

            // 爆発するときに Instantiate() したいのですが、 Destroy() の前に記載
            // 位置と回転は、このスクリプトが割り当てられている敵の位置と敵の回転をそのまま使えば良いので、これで OK
            Instantiate(explosion, transform.position, transform.rotation);

            // 弾と当たったときの処理、弾も敵も消してあげたいので Destroy() を使用

            // 弾のほうは collision で拾えるので Destroy(collision.gameObject); としつつ
            Destroy(collision.gameObject);

            // 自分自身、つまり敵のオブジェクトを消すには Destroy(gameObject); と書いてあげれば OK
            Destroy(gameObject);
        }


        // EnemyScript で Player と当たったとき、と書いていきたいので EnemyScript を編集していきます
        // CompareTag("Player") としつつ、インスタンス化するのは explosion と、もうひとつ explosion を Player の位置に出したいのでコピーしてあげつつ、位置と回転を collision のものを使ってあげればOK

        if (collision.gameObject.CompareTag("Player"))
        {
            // EnemyScript で Player と衝突したときにゲームオーバーにすればいいので、このあたりに記載し、gameController はもう取得できているので gameController の GameOver() メソッドを呼んであげれば OK
            gameController.GameOver();

            Instantiate(explosion, transform.position, transform.rotation);
            Instantiate(explosion, collision.transform.position, collision.transform.rotation);
            Destroy(collision.gameObject);
            Destroy(gameObject);
        }
    }
Ejemplo n.º 14
0
 public void OnClicked()
 {
     Destroy(gameObject);
     gameController.AddScore(10);
 }