Exemple #1
0
        private void Shoot()
        {
            GameObject shot = Instantiate(projectilePrefab) as GameObject;

            shot.transform.position = this.transform.position;

            DemoPlayerShotScript shotScript = shot.GetComponent <DemoPlayerShotScript>();

            shotScript.speed = new Vector2(25, 0);
        }
        void OnTriggerEnter2D(Collider2D otherCollider)
        {
            // Collision with player projectile
            DemoPlayerShotScript playerShot = otherCollider.GetComponent <DemoPlayerShotScript>();

            if (playerShot != null)
            {
                hp--;

                DestroyObject(playerShot.gameObject);

                // Flash red
                StartCoroutine(FlashRed());

                if (hp == 0)
                {
                    Destroy(this.gameObject);
                }
            }
        }