void OnTriggerEnter2D(Collider2D coll)
    {
        //reset the boid to a random location
        Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0.0F, Screen.width), Random.Range(0.0F, Screen.height), 0));

        pos.z = 0f;
        coll.transform.position = pos;
        coll.GetComponent <Rigidbody2D> ().velocity = new Vector3(Random.Range(-1.0F, 1.0F), Random.Range(-1.0F, 1.0F), Random.Range(0.0F, 1.0F));

        scoreScript.UpdateScore();

        switch (type)
        {
        case 0:
            data.UpdateControl(scoreScript.score);
            break;

        case 1:
            data.UpdateFlock(scoreScript.score);
            break;

        case 2:
            data.UpdateSwarm(scoreScript.score);
            break;

        case 3:
            data.UpdateFirefly(scoreScript.score);
            break;
        }
    }
Esempio n. 2
0
    void OnTriggerEnter2D(Collider2D coll)
    {
        Vector3 pos        = new Vector3();
        int     caseSwitch = Random.Range(1, 5);

        // spawns randomly along edges of screen
        switch (caseSwitch)
        {
        case 1:     // bottom edge of screen
            pos = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0, Screen.width), 0));
            break;

        case 2:     // top edge of screen
            pos = Camera.main.ScreenToWorldPoint(new Vector3(Random.Range(0, Screen.width), Screen.height));
            break;

        case 3:     // left edge of screen
            pos = Camera.main.ScreenToWorldPoint(new Vector3(0, Random.Range(0, Screen.height)));
            break;

        case 4:     // right edge of screen
            pos = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Random.Range(0, Screen.height)));
            break;
        }

        pos.z = 0f;
        coll.transform.position = pos;
        coll.GetComponent <Rigidbody2D>().velocity = new Vector3(Random.Range(-1.0F, 1.0F), Random.Range(-1.0F, 1.0F), Random.Range(0.0F, 1.0F));

        scoreScript.UpdateScore();


        switch (type)
        {
        case 0:
            data.UpdateControl(scoreScript.score);
            break;

        case 1:
            data.UpdateFlock(scoreScript.score);
            break;

        case 2:
            data.UpdateSwarm(scoreScript.score);
            break;

        case 3:
            data.UpdateFirefly(scoreScript.score);
            break;
        }
    }