Beispiel #1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Food")
        {
            movement.AddBodyPart();

            gm.AddScore();
            gm.AddCollected();

            Destroy(collision.gameObject);

            //SO.SpawnFood();
        }

        else
        {
            if (collision.transform != movement.BodyParts[1] && movement.isAlive)
            {
                if (Time.time - movement.TimeFromLastRetry > 1)
                {
                    Debug.Log("collision with smth");
                    movement.Die();
                }
            }
        }
    }
Beispiel #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "food")
     {
         movement.AddBodyPart();
         Destroy(other.gameObject);
         sp.SpawnFoods(); sp.SpawnFoods();
     }
 }
Beispiel #3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (SM.BodyParts.Count > 0)
     {
         if (collision.transform.tag == "Food" && transform == SM.BodyParts [0])
         {
             for (int i = 0; i < collision.transform.GetComponent <FoodBehaviour>().foodAmount; i++)
             {
                 SM.AddBodyPart();
             }
             Destroy(collision.transform.gameObject);
         }
     }
 }
Beispiel #4
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Food")
        {
            snakeMovement.AddBodyPart();

            Destroy(collision.gameObject);
            spwanFood.SpwanFoodObject();
        }
        else if (collision.transform != snakeMovement.BodyPartsList[1] && snakeMovement.isAlive)
        {
            if (Time.time - snakeMovement.TimeFromLastRetry > 5)
            {
                snakeMovement.Die();
            }
        }
    }
Beispiel #5
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //If we collide with the food
        if (SM.BodyParts.Count > 0)
        {
            if (collision.transform.tag == "Food" && transform == SM.BodyParts[0])
            {
                //Add a body part, will be changed to the amount of body parts it has to add
                for (int i = 0; i < collision.transform.GetComponent <FoodBehavior>().foodAmount; i++)
                {
                    SM.AddBodyPart();
                }

                //Destroy the food
                Destroy(collision.transform.gameObject);
            }
        }
    }