예제 #1
0
    void OnTriggerEnter(Collider other)
    {
        // layer 9 is a fruit layer to know if there is a fruit inside the trigger or a snake body
        if (other.gameObject.layer == 9)
        {
            // destroy fruit game object
            Destroy(other.gameObject);

            // call add body function inside the snake class
            snake_cla.Add_body();

            // increase ths score by 10
            game_man.add_score(10);

            // spawn a new fruit
            game_man.spawn_fruit();

            // add the value to all_count
            all_count += 10;
        }

        // layer 8 is snake body layer
        if (other.gameObject.layer == 8)
        {
            // disable the snake class to stop the movement of the snake
            snake.GetComponent <snake> ().enabled = false;

            // active the dead menu contain ( Gameover statement & restart button & back to menu button  )
            btn_manage = M_camera.GetComponent <button_manager> ();
            btn_manage.dead_menu_option(true);
            game_man.add_score(-all_count);
        }
    }
예제 #2
0
    void Start()
    {
        all_count = 0;

        game_man = game_manager.GetComponent <game_manager> ();
        M_camera = GameObject.FindWithTag("MainCamera");

        // get the snake class to cll add function when the snake eat fruit
        snake_cla = snake.GetComponent <snake> ();

        // spawn a new fruit after eating the last one
        game_man.spawn_fruit();
    }