Ejemplo n.º 1
0
    public void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "target")
        {
            string targetname = collision.gameObject.name;


            GameObject targetobject = GameObject.Find(targetname);

            target = targetobject.GetComponent<Target>();
            //Debug.Log(target.GetComponent<Renderer>().material.color == Color.red);
            if (target.GetComponent<Renderer>().material.color == Color.red)
            {
                if (colcount >= target.collisionsRequired)
                {
                    target.GetComponent<Renderer>().material.color = Color.green;
                    target.Invoke("openDoor", 1);
                    score = 500 + 500* colcount;
                    
                    GameObject scoretextobject = GameObject.Find("Score");
                    Text scoretext = scoretextobject.GetComponentInChildren<Text>();
                    float currentScore = Single.Parse(scoretext.text);
                    score += currentScore;
                    scoretext.text = score.ToString();

                }
                else
                {
                    target.playSound("miss");
                    target.GetComponent<Renderer>().material.color = Color.yellow;
                    Invoke("changeRed", 2);

                }
            }
        }

        else
        {
            GetComponent<AudioSource>().Play();
            colcount++;

        }


    }