Пример #1
0
    }    //collisionEnter2d

    void OnExplode()
    {
        Destroy(gameObject);
        var trans = transform;

        for (int i = 0; i < 5; i++)
        {
            //trans.TransformPoint(randomX,randomY,0);
            var temp = trans.position;
            temp.x += (0.5f * Random.Range(-1, 1));
            //temp.y += (0.5f * Random.Range(-1,1));
            BoxParts clone = Instantiate(bodyParts, temp, Quaternion.identity) as BoxParts;
            // adding force to sideways
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.right * Random.Range(-50, 50));
            //adding force to up
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.up * Random.Range(50, 300));
        } //loop of explode
    }     //onexplode
Пример #2
0
    }    // gameover

    void DieAndExplode()
    {
        if (isSoundOn)
        {
            AudioSource.PlayClipAtPoint(dieSoundClip, transform.position);
        }
        Destroy(gameObject);
        var trans = transform;

        for (int i = 0; i < 7; i++)
        {
            //trans.TransformPoint(randomX,randomY,0);
            var temp = trans.position;
            temp.x += (0.5f * Random.Range(-1, 1));
            //temp.y += (0.5f * Random.Range(-1,1));
            BoxParts clone = Instantiate(bodyParts, temp, Quaternion.identity) as BoxParts;
            // adding force to sideways
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.right * Random.Range(-50, 50));
            //adding force to up
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.up * Random.Range(50, 300));
        }        //loop of explode
    }