예제 #1
0
    public void Die()
    {
        Rigidbody  playerShipRB = playerShip.GetComponent <Rigidbody>();
        Vector3    baseVelocity = playerShipRB.velocity;
        Vector3    shipPosition = playerShip.transform.position;
        Quaternion shipRotation = playerShip.transform.rotation;

        playerShip.GetComponent <PlayerController>().StopMovement();
        playerShip.SetActive(false);

        playerShipBroken.transform.position = shipPosition;
        playerShipBroken.transform.rotation = shipRotation;
        playerShipBroken.SetActive(true);
        AudioSource audioSource = playerShipBroken.GetComponent <AudioSource>();

        SoundManager.Instance.PlaySFX(audioSource);

        for (int i = 0; i < playerShipBroken.transform.childCount; i++)
        {
            GameObject child = playerShipBroken.transform.GetChild(i).gameObject;
            if (child.tag == GameManager.Instance.GetShipModuleTag())
            {
                RandomSpacePusher randomPusher = child.GetComponent <RandomSpacePusher>();
                randomPusher.SetMomentum(baseVelocity, momentumDampeningFactor);
                randomPusher.GivePush();

                child.transform.localPosition = fragmentPositions[i];
            }
        }

        dead = true;
        LivesManager.Instance.RemoveLife();
        shipCollider.enabled = false;
        if (!LivesManager.Instance.IsGameover())
        {
            StartCoroutine(WaitToRespawn());
        }
        else
        {
            StartCoroutine(WaitToGameOver());
        }
    }
예제 #2
0
    private void SpawnAsteroid(Vector3 spawnPosition, AsteroidData asteroidData)
    {
        GameObject asteroid = PoolsManager.Instance.GetAsteroidsPool().GetAvailable();

        asteroid.transform.position = spawnPosition;
        asteroid.transform.rotation = Random.rotation;

        asteroid.SetActive(true);

        Rigidbody asteroidRB = asteroid.GetComponent <Rigidbody>();

        asteroidRB.mass = asteroidData.GetMass();
        RandomSpacePusher randomPusher = asteroid.GetComponent <RandomSpacePusher>();

        randomPusher.SetRandomPush(pushForce, angularVelocity);
        randomPusher.GivePush();
        AsteroidController asteroidController = asteroid.GetComponent <AsteroidController>();

        asteroidController.Init(asteroidData);
    }