コード例 #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Meteorite"))
        {
            Meteorite meteorite = collision.gameObject.GetComponent <Meteorite>();

            if (meteorite != null)
            {
                FindObjectOfType <Score>().AddPoints(10);

                meteorite.DestroyMeteorite();
                GameObject particles = Instantiate(hitParticlesPrefab, transform.position, transform.rotation);
                Destroy(particles, 5f);
                Destroy(this.gameObject);
            }
        }

        if (collision.gameObject.CompareTag("Enemy"))
        {
            Enemy enemy = collision.gameObject.GetComponent <Enemy>();

            if (enemy != null)
            {
                FindObjectOfType <Score>().AddPoints(20);

                enemy.Damage(damageAmount);
                GameObject particles = Instantiate(hitParticlesPrefab, transform.position, transform.rotation);
                Destroy(particles, 5f);
                Destroy(this.gameObject);
            }
        }
    }
コード例 #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Meteorite"))
        {
            Meteorite meteorite = collision.gameObject.GetComponent <Meteorite>();


            if (meteorite != null)
            {
                FindObjectOfType <Score>().AddPoints(10);
                meteorite.DestroyMeteorite();
            }
        }

        GameObject particles = Instantiate(hitParticlePrefab, transform.position, transform.rotation);

        Destroy(particles, 5f);
        Destroy(this.gameObject);
    }