Пример #1
0
    void Update()
    {
        if (tienesUnObjeto)
        {
            objetoActual.CarryObject();

            //Tirar arma
            if (characterController.inputPickWeapon)
            {
                objetoActual.ThrowObject();

                tienesUnObjeto = false;

                GameObject       gameObj   = Instantiate(instantiateObject, weaponUsePosition.position, transform.rotation) as GameObject;
                Rigidbody2D      gameObjrb = gameObj.GetComponent <Rigidbody2D>();
                WeaponController gameObjWc = gameObj.GetComponent <WeaponController>();

                gameObjWc.itemIndex = characterController.playerIndex;

                gameObjrb.AddForce(new Vector2(5f * characterController.characterDir, 5f), ForceMode2D.Impulse);
                gameObjrb.AddTorque(Random.Range(0.1f, 0.3f) * -characterController.characterDir, ForceMode2D.Impulse);

                weaponName        = "";
                weaponSprite      = null;
                instantiateObject = null;

                gameObjWc.StartCoroutine("EnfriamientoCogerObjeto");
            }



            //Usar arma
            if (characterController.inputUseWeapon)
            {
                objetoActual.UseObject();

                //Variables del animator
                characterAnimator.SetTrigger("ThrowObject");

                switch (weaponName)
                {
                case "Bottle":
                    GameObject       bottle   = Instantiate(instantiateObject, weaponUsePosition.position, transform.rotation) as GameObject;
                    Rigidbody2D      bottlerb = bottle.GetComponent <Rigidbody2D>();
                    WeaponController bottlewc = bottle.GetComponent <WeaponController>();

                    bottlerb.AddForce(new Vector2(10f * characterController.characterDir, 5f), ForceMode2D.Impulse);
                    bottlerb.AddTorque(Random.Range(0.1f, 0.5f) * characterController.characterDir, ForceMode2D.Impulse);

                    bottlewc.isItem    = false;
                    bottlewc.itemIndex = characterController.playerIndex;

                    break;

                case "Orange":
                    GameObject       orange   = Instantiate(instantiateObject, weaponUsePosition.position, transform.rotation) as GameObject;
                    Rigidbody2D      orangerb = orange.GetComponent <Rigidbody2D>();
                    WeaponController orangewp = orange.GetComponent <WeaponController>();

                    orangerb.AddForce(new Vector2(10f * characterController.characterDir, 10f), ForceMode2D.Impulse);
                    orangerb.AddTorque(Random.Range(0.1f, 0.5f) * -characterController.characterDir, ForceMode2D.Impulse);

                    orangewp.isItem    = false;
                    orangewp.itemIndex = characterController.playerIndex;

                    break;
                }

                tienesUnObjeto = false;

                weaponName        = "";
                weaponSprite      = null;
                instantiateObject = null;
            }

            weaponIconPosition.gameObject.GetComponent <SpriteRenderer>().sprite = weaponSprite;
        }
    }