public void eatFood(Vector3 snakeHeadPosition)
    {
        positionRecord snakeHeadPos = new positionRecord();

        snakeHeadPos.Position = snakeHeadPosition;

        int foodIndex = allTheFood.IndexOf(snakeHeadPos);

        if (foodIndex != -1)
        {
            Destroy(allTheFood[foodIndex].BreadcrumbBox);

            //  allTheFood.RemoveAt(foodIndex);

            scoreManager.scoreValue++;

            sn.snakelength++;



            //if I have a list as follows

            //1. = 0 positionRecord1 in Vector3(0f,0f);
            //2. Vector3(1,0)
            //3. VEctor3(2,0)

            //indexof(0,0) = 0

            //indexof(-5,2) = -1


            if (foodIndex != -1)
            {
                Color foodColor;

                foodColor = allTheFood[foodIndex].BreadcrumbBox.GetComponent <SpriteRenderer>().color;

                sn.changeSnakeColor(sn.snakelength, foodColor);

                Destroy(allTheFood[foodIndex].BreadcrumbBox);

                allTheFood.RemoveAt(foodIndex);

                sn.snakelength++;
            }
        }
    }
Beispiel #2
0
    public void eatFood(Vector3 snakeHeadPosition)
    {
        positionRecord snakeHeadPos = new positionRecord();

        snakeHeadPos.Position = snakeHeadPosition;

        int foodIndex = allTheFood.IndexOf(snakeHeadPos);


        if (foodIndex != -1)
        {
            Color foodColor;

            foodColor = allTheFood[foodIndex].BreadcrumbBox.GetComponent <SpriteRenderer>().color;

            sn.changeSnakeColor(sn.snakelength, foodColor);

            Destroy(allTheFood[foodIndex].BreadcrumbBox);

            allTheFood.RemoveAt(foodIndex);

            sn.snakelength++;
        }
    }