Esempio n. 1
0
    private void OnTriggerEnter(Collider coll)
    {
        // Trigger Food?
        if (coll.name.StartsWith("FoodPrefab"))
        {
            //dis = Vector3.Distance(coll.transform.position, rb.transform.position);
            Vector3 move_force = rb.transform.position - coll.transform.position;
            coll.GetComponent <Rigidbody>().AddForce(move_force * 10);

            rotateFood fd = coll.gameObject.GetComponent <rotateFood>();

            fd.ate_by_worm();

            ate -= 24;
        }
        if (coll.name.StartsWith("fd"))
        {
            //dis = Vector3.Distance(coll.transform.position, rb.transform.position);
            Vector3 move_force = rb.transform.position - coll.transform.position;
            coll.GetComponent <Rigidbody>().AddForce(move_force * 10);

            rotateFood fd = coll.gameObject.GetComponent <rotateFood>();

            fd.fd_ate_by_worm();

            ate -= 20;
        }

        // When current worm collides against tail of another worm
        if (coll.name.StartsWith("tail") && !coll.name.EndsWith("[" + Head_index + "]"))
        {
            die = true;
        }
    }
Esempio n. 2
0
    private void OnTriggerEnter(Collider coll)
    {
        // Trigger Food?
        if (coll.name.StartsWith("FoodPrefab"))
        {
            //dis = Vector3.Distance(coll.transform.position, rb.transform.position);
            Vector3 move_force = rb.transform.position - coll.transform.position;
            coll.GetComponent <Rigidbody>().AddForce(move_force * 10);

            GameObject fd = coll.gameObject;

            fd.GetComponent <rotateFood>().ate_by_worm();
            int ScoreGet = fd.GetComponent <foodinfo>().score;

            ate -= ScoreGet;
            SFXplayer.PlayEatSound();
            score += ScoreGet;
            if (jo != null)
            {
                jo.Call("updateScore", Head_index + " " + score);
            }

            return;
        }
        else if (coll.name.StartsWith("fd"))
        {
            SFXplayer.PlayEatSound();
            //dis = Vector3.Distance(coll.transform.position, rb.transform.position);
            Vector3 move_force = rb.transform.position - coll.transform.position;
            coll.GetComponent <Rigidbody>().AddForce(move_force * 10);

            rotateFood fd = coll.gameObject.GetComponent <rotateFood>();

            fd.fd_ate_by_worm();

            ate -= 20;

            score += 20;
            if (jo != null)
            {
                jo.Call("updateScore", Head_index + " " + score);
            }

            return;
        }
        if (coll.name.StartsWith("tail") && !coll.name.EndsWith("[" + Head_index + "]"))
        {
            die = true;
            return;
        }
        // Collided with Tail or Border
    }