コード例 #1
0
    void OnCollisionEnter(Collision collision)
    {
        audience = new GameObject[] { audience1, audience2, audience3, audience4, audience5, audience6, audience7, audience8 };      //, audience9, audience10}
        score    = 0;
        ContactPoint contact = collision.contacts[0];
        Vector3      pos     = contact.point;

        point_x = pos.x;
        point_y = pos.y;
        //TODO assign Points x,y and Origin x,y
        float dist = Mathf.Sqrt(((point_y - origin_y) * (point_y - origin_y)) + ((point_x - origin_x) * (point_x - origin_x)));

        if (dist <= outer_b_r)
        {
            if (dist <= inner_b_r)
            {
                score = 50;
            }
            else
            {
                score = 25;
            }
        }
        else
        {
            float angle = (Mathf.Atan2((point_y - origin_y), (point_x - origin_x)) * 180) / Mathf.PI;
            if ((point_y < origin_y))
            {
                angle += 360;
            }
            angle += 9;
            int index   = ((int)(angle / 18)) % 20;
            int section = val_scores[index];
            Debug.Log("ANGLE IS -------- : " + angle);

            if (dist <= inner_single_r)
            {
                score = section;
            }
            else if (dist <= triple_r)
            {
                score = 3 * section;
            }
            else if (dist <= outer_single_r)
            {
                score = section;
            }
            else if (dist <= double_r)
            {
                score = 2 * section;
            }
            else
            {
                score = 0;
            }
        }
        if (dist <= t_radius)
        {
            collision.collider.GetComponent <Rigidbody>().velocity        = Vector3.zero;
            collision.collider.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
            collision.collider.GetComponent <Rigidbody>().isKinematic     = true;
            this.gameObject.GetComponent <AudioSource> ().Play();
        }
        //scoreboard.GetComponent<SumScore>().Add(score);
        SumScore.IncrementDartCount();
        if (SumScore.Score - score > 0)
        {
            SumScore.Subtract(score);
            if (score != 0)
            {
                foreach (GameObject aud in audience)
                {
                    aud.GetComponent <Animation> ().Play("applause");
                }
            }
        }
        else if (SumScore.Score - score == 0)
        {
            SumScore.Subtract(score);
            SumScore.SaveHighScore(SumScore.DartScore);
            SumScore.Reset();
            SumScore.Add(101);
            foreach (GameObject aud in audience)
            {
                aud.GetComponent <Animation> ().Play("celebration");
            }
        }
        else
        {
            SumScore.Subtract(0);
            Debug.Log("Last dart score must be equal to remaining score");
        }
    }