Esempio n. 1
0
    public void OnCollisionEnter(Collision coll)
    {
        // If this is the child of another Asteroid, pass this collision up the chain
        if (parentIsAsteroid)
        {
            parentAsteroid.OnCollisionEnter(coll);
            return;
        }

        if (immune)
        {
            return;
        }

        GameObject otherGO = coll.gameObject;

        if (otherGO.tag == "Bullet" || otherGO.transform.root.gameObject.tag == "Player")
        {
            if (otherGO.tag == "Bullet")
            {
                Destroy(otherGO);
                AsteraX.AddScore(AsteraX.AsteroidsSO.pointsForAsteroidSize[size]);

                AchievementManager.AchievementStep(Achievement.eStepType.hitAsteroid, 1);

                Bullet bul = otherGO.GetComponent <Bullet>();
                if (bul != null)
                {
                    if (bul.bDidWrap)
                    {
                        AchievementManager.AchievementStep(Achievement.eStepType.luckyShot);
                    }
                }
            }

            if (size > 1)
            {
                // Detach the children Asteroids
                Asteroid[] children = GetComponentsInChildren <Asteroid>();
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].immune = true;
                    if (children[i] == this || children[i].transform.parent != transform)
                    {
                        continue;
                    }
                    children[i].transform.SetParent(null, true);
                    children[i].InitAsteroidParent();
                }
            }

            InstantiateParticleSystem();
            Destroy(gameObject);
        }
    }
Esempio n. 2
0
    public void OnCollisionEnter(Collision coll)
    {
        // If this is the child of another Asteroid, pass this collision up the chain
        if (parentIsAsteroid)
        {
            parentAsteroid.OnCollisionEnter(coll);
            return;
        }

        if (immune)
        {
            return;
        }

        GameObject otherGO = coll.gameObject;

        if (otherGO.tag == "Bullet" || otherGO.transform.root.gameObject.tag == "Player")
        {
            if (otherGO.tag == "Bullet")
            {
                Destroy(otherGO);
                AsteraX.AddScore(AsteraX.AsteroidsSO.pointsForAsteroidSize [size]);
            }

            if (otherGO.tag == "Player")
            {
                PlayerShip ship = otherGO.GetComponent <PlayerShip> ();
                ship.Jump();
            }

            if (size > 1)
            {
                // Detach the children Asteroids
                Asteroid[] children = GetComponentsInChildren <Asteroid>();
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].immune = true;
                    if (children[i] == this || children[i].transform.parent != transform)
                    {
                        continue;
                    }
                    children[i].transform.SetParent(null, true);
                    children[i].InitAsteroidParent();
                }
            }

            Destroy(gameObject);
        }
    }