Esempio n. 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.tag == "Food" && !IsStunned)      // if the player collides with a food object
        {
            // Check if there's room in the player inventory
            if (currentLoad < invSize)
            {
                PlayerCamera pcScript = PlayerUI.GetComponent <PlayerCamera>();
                pcScript.AddFood(collision.gameObject);
                currentLoad++;
            }
        }

        else if (collision.transform.tag == "Guard")    // if the player collides with a guard
        {
            //IsStunned = true;
            // Launch food in a directions
            PlayerCamera pcScript = PlayerUI.GetComponent <PlayerCamera>();
            for (int i = currentLoad; i > 0; i--)
            {
                // generate a random vector and speed to launch the food
                Vector2 randDir = new Vector2();
                randDir.x = Random.Range(-2.0f, 2f);
                randDir.y = Random.Range(-2.0f, 2f);
                float rSpeed = Random.Range(8f, 16f);

                LaunchFood(pcScript.RemoveFood(), randDir, rSpeed);
                currentLoad--;
            }
            // Stun the player momentarily
        }
    }