Ejemplo n.º 1
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        if (isFlying)
        {
            WinPortal winPortal = collision.collider.GetComponent <WinPortal>();
            if (winPortal)
            {
                // YOU WIN!!!!
                Debug.Log("You win!!!!");

                isFlying = false;

                gameObject.SetActive(false);

                LevelSystem.FinishLevel();

                return;
            }

            // fuel pickups are handled in fuelpickup.cs.ontriggerenter (cause they have trigger volumes)


            // create our explosion and our dead space man
            if (explosionPrefab)
            {
                GameObject goExplosion = GameObject.Instantiate <GameObject>(explosionPrefab, transform.position, Quaternion.identity, null);
            }

            if (deadSpacemanPrefab)
            {
                GameObject goSpaceman = GameObject.Instantiate <GameObject>(deadSpacemanPrefab, transform.position, Quaternion.identity, null);
            }

            GameCamera.Current.Shake(deathShakePower, deathShakeDuration);

            SetThrusters(false);

            numTimesDied++;

            // hide our model
            model.SetActive(false);
            fuelgauge.SetActive(false);
            isFlying       = false;
            body.simulated = false;

            ResetShip();
        }
    }
Ejemplo n.º 2
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        if (canGo)
        {
            WinPortal winPortal = collision.collider.GetComponent <WinPortal>();
            if (winPortal)
            {
                // YOU WIN!!!!
                Debug.Log("You win!!!!");

                canGo = false;

                gameObject.SetActive(false);

                return;
            }

            // fuel pickups are handled in fuelpickup.cs.ontriggerenter (cause they have trigger volumes)

            // TODO: YOU LOOSE!!

            // create our explosion and our dead space man
            if (explosionPrefab)
            {
                GameObject goExplosion = GameObject.Instantiate <GameObject>(explosionPrefab, transform.position, Quaternion.identity, null);
            }

            if (deadSpacemanPrefab)
            {
                GameObject goSpaceman = GameObject.Instantiate <GameObject>(deadSpacemanPrefab, transform.position, Quaternion.identity, null);
                // add a tiiiny amount of force to him, so he'll float
                Rigidbody2D spacemanBody = goSpaceman.GetComponent <Rigidbody2D>();
                if (spacemanBody)
                {
                    float forcePower = Random.Range(.1f, 1f);
                    spacemanBody.AddForce(new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)), ForceMode2D.Impulse);
                }
            }

            SetThrusters(false);

            // hide our model
            model.SetActive(false);
            canGo          = false;
            body.simulated = false;
        }
    }