Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        instance   = this;
        playerDied = false;
        timer      = 0f;

#if UNITY_EDITOR
        Configuration.Load();
        Application.targetFrameRate = Screen.currentResolution.refreshRate;
#endif
        Vector2 camSize = new Vector2();
        camSize.y = mainCamera.orthographicSize;
        camSize.x = camSize.y * mainCamera.aspect;
        Vector2 camPos = mainCamera.transform.position;

        if (backgroundSprite.gameObject.activeSelf)
        {
            Vector2 bgMoveLimit = (Vector2)backgroundSprite.bounds.extents - camSize;
            Vector3 bgMove      = new Vector3(Random.Range(-bgMoveLimit.x, bgMoveLimit.x), Random.Range(-bgMoveLimit.y, bgMoveLimit.y));
            backgroundSprite.transform.Translate(bgMove);
        }
        if (skybox.activeSelf)
        {
            skybox.transform.rotation = Random.rotationUniform;
            skyboxRotationAxis        = Random.onUnitSphere;
        }

        cameraVisibility = new Rect(camPos - camSize, camSize + camSize);
        mainCamera.GetComponent <BoxCollider2D>().size = camSize + camSize;
    }
Example #2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject collidee = collision.gameObject;

        if (!dead && collidee.CompareTag("Asteroid"))
        {
            dead = true;
            GameObject particles = Instantiate(explodeEffectPrefab, transform.position, Quaternion.identity).gameObject;
            Destroy(gameObject, 0.15f);
            Destroy(particles, 4f);
            GameControlLaser.PlayerDied();
        }
    }