//lr.materials[0].color = new Color(1, 0, 0);



    void Update()
    {
        if (Input.GetKeyDown("s"))
        {
            startTime = Time.time;
            foreach (GameObject ball in NumberBallList)
            {
                NumberBall script = ball.GetComponent <NumberBall>();
                script.startTime = startTime;
            }
        }

        time = Time.time - startTime;



        if (NumberBallList.Count >= 1 && startTime > 0)
        {
            circleNumber.Value = (int)(time / unitTime);
            //foreach (GameObject ball in NumberBallList)
            //{
            //	NumberBall script = ball.GetComponent<NumberBall>();
            //	script.SetPosition(time);
            //}
        }
    }
Пример #2
0
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.tag == "NumberBall")
        {
            Destroy(this.gameObject);
            GameObject hitBall = col.gameObject;

            // Now we test to see if the hit is a valid one, given the prime number and the number ball
            NumberBall nb            = hitBall.GetComponent <NumberBall> ();
            int        hitBallNumber = nb.getNumber();

            if (hitBallNumber % number == 0)     // if the number divides exactly
            {
                if (isStunner)                   // just stun
                {
                    hitBall.GetComponent <Rigidbody> ().constraints = RigidbodyConstraints.FreezeAll;
                }
                else                     // actually destroy or reduce value of hit ball
                {
                    int newValue = hitBallNumber / number;
                    if (newValue == 1)
                    {
                        GameObject.FindGameObjectWithTag("Spawner").GetComponent <BallSpawner> ()
                        .CreateInstanceAfterDelay(hitBall.transform.position.x);
                        hitBall.GetComponent <AudioSource> ().Play();                         // TODO get this to actually play something. I believe the problem is that the object
                        // is deleted before the sound finishes playing.
                        Destroy(hitBall);
                        GameManager.increaseScore(nb.getScoreValue());
                    }
                    else
                    {
                        nb.setNumber(newValue);
                    }
                }
            }
            else                 // TODO have some cool effect or 'error' sound
            {
            }
        }
        else if (col.gameObject.tag == "EndOfWorld")             // hit the back boundary or the floor
        {
            Destroy(this.gameObject);
        }
    }