예제 #1
0
    public void OnCollision2D(Collision2D collider)
    {
        if (!wasCollision && collider.gameObject.tag != "Catapult")
        {
            // GameObject.Find("Manager").GetComponent<ObjectManagerScript>().SetNextVagetable();
            wasCollision = true;
        }
        int damage;

        switch (collider.gameObject.tag)
        {
        case "Block":
            BlockClass block = collider.gameObject.GetComponent <BlockController>().Block;
            damage = Mathf.RoundToInt(Damage *
                                      (block.CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude +
                                       CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.velocity.magnitude) * PhysicsConstants.MagnitudeCoefficient *
                                      CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.mass *PhysicsConstants.MassCoefficient);
            block.Health -= damage;

            Debug.Log("Vegetable to block   :   " + damage);

            block.CheckHealth();
            break;

        case "Meat":
            MeatClass meat = collider.gameObject.GetComponent <MeatController>().Meat;
            damage = Mathf.RoundToInt(Damage *
                                      (meat.CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude +
                                       CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.velocity.magnitude) * PhysicsConstants.MagnitudeCoefficient *
                                      CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.mass *PhysicsConstants.MassCoefficient);
            meat.Health -= damage;

            Debug.Log("Vegetable to meat   :   " + damage);

            meat.CheckHealth();
            break;

        case "Catapult":

            break;

        case "Vegetable":

            break;

        default:
            damage = Mathf.RoundToInt(PhysicsConstants.DefaultDamage *
                                      CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.velocity.magnitude *PhysicsConstants.MagnitudeCoefficient *
                                      CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.mass *PhysicsConstants.MassCoefficient);
            Health -= damage;

            Debug.Log("Default to vegetable   :   " + damage);

            CheckHealth();
            break;
        }
    }
예제 #2
0
 public void AddMeat(MeatClass Meat, Vector2 Position)
 {
     Meat.Position = Position;
     Meats.Add(Meat);
 }
        public virtual void OnCollision2D(Collision2D collision)
        {
            int damage;

            switch (collision.gameObject.tag)
            {
            case "Vegetable":
                VegetableClass vegatable = collision.gameObject.GetComponent <VegetableController>().Vegetable;
                damage = Mathf.RoundToInt(Damage *
                                          (vegatable.CurrentGameObject.GetComponent <VegetableController>().Rigidbody2D.velocity.magnitude +
                                           CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude) * PhysicsConstants.MagnitudeCoefficient *
                                          CurrentGameObject.GetComponent <Rigidbody2D>().mass *PhysicsConstants.MassCoefficient);
                vegatable.Health -= damage;
                vegatable.CheckHealth();

                Debug.Log("Block to vegetable   :   " + damage);

                CurrentGameObject.GetComponent <SoundManagerComponent>().PlaySound(CollisionSound);
                break;

            case "Block":
                BlockClass block = collision.gameObject.GetComponent <BlockController>().Block;
                damage = Mathf.RoundToInt(Damage *
                                          (block.CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude +
                                           CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude) * PhysicsConstants.MagnitudeCoefficient *
                                          CurrentGameObject.GetComponent <Rigidbody2D>().mass *PhysicsConstants.MassCoefficient);
                block.Health -= damage;
                block.CheckHealth();

                Debug.Log("Block to block   :   " + damage);

                CurrentGameObject.GetComponent <SoundManagerComponent>().PlaySound(CollisionSound);
                break;

            case "Meat":
                MeatClass meat = collision.gameObject.GetComponent <MeatController>().Meat;
                damage = Mathf.RoundToInt(Damage *
                                          (meat.CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude +
                                           CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude) * PhysicsConstants.MagnitudeCoefficient *
                                          CurrentGameObject.GetComponent <Rigidbody2D>().mass *PhysicsConstants.MassCoefficient);
                meat.Health -= damage;

                Debug.Log("Block to meat   :   " + damage);

                meat.CheckHealth();
                break;

            default:
                if (isFirstCollision)
                {
                    damage = Mathf.RoundToInt(PhysicsConstants.DefaultDamage *
                                              CurrentGameObject.GetComponent <Rigidbody2D>().velocity.magnitude *PhysicsConstants.MagnitudeCoefficient *
                                              CurrentGameObject.GetComponent <Rigidbody2D>().mass *PhysicsConstants.MassCoefficient);
                    Health -= damage;

                    Debug.Log("Default to block   :   " + damage);

                    CheckHealth();
                }
                else
                {
                    isFirstCollision = true;
                }
                break;
            }
        }