Esempio n. 1
0
    void Start()
    {
        // retrieving the playerShip and playerShipBroken objects
        for (int i = 0; i < transform.childCount; i++)
        {
            GameObject child = transform.GetChild(i).gameObject;
            if (child.tag == GameManager.Instance.GetPlayerShipTag())
            {
                playerShip = child;
            }
            else if (child.tag == GameManager.Instance.GetPlayerShipBrokenTag())
            {
                playerShipBroken = child;
            }
        }

        shipCollider         = playerShip.GetComponent <BoxCollider>();
        shipCollider.enabled = false;

        // storing the original fragment local position
        fragmentPositions = new Vector3[playerShipBroken.transform.childCount];
        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.SetRandomPush(fragmentsPushForce, fragmentsAngularVelocity);

                fragmentPositions[i] = child.transform.localPosition;
            }
        }
    }
Esempio n. 2
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());
        }
    }
Esempio n. 3
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);
    }