예제 #1
0
    // gestione dell'interazione con l'arma
    private void ManageWeaponInteraction(WeaponProps weapon)
    {
        if (weapon._name == "Granade")
        {
            if (!granadeHolderManager.IsWeaponFull(weapon._name))
            {
                textWindow.alpha       = 1;
                buttonToPressText.text = "Press \"E\" button to pick ammo";

                if (Input.GetButtonDown("Interact"))
                {
                    granadeHolderManager.RefillAmmoToWeapon(weapon._name, weapon._currentChargerAmmo);
                    Destroy(objectToDescribe);
                    DisableWindow();
                    //Debug.Log("Premuto il tasto e 1");
                }
            }
        }
        else
        {
            if (weaponHolderManager.IsUnlocked(weapon._name) && !weaponHolderManager.IsWeaponFull(weapon._name))
            {
                textWindow.alpha       = 1;
                buttonToPressText.text = "Press \"E\" button to pick ammo";

                if (Input.GetButtonDown("Interact"))
                {
                    weaponHolderManager.RefillAmmoToWeapon(weapon._name, weapon._currentChargerAmmo);
                    Destroy(objectToDescribe);
                    DisableWindow();
                    //Debug.Log("Premuto il tasto e 1");
                }
            }
            else if (!weaponHolderManager.IsUnlocked(weapon._name))
            {
                textWindow.alpha       = 1;
                buttonToPressText.text = "Press \"E\" button to grab the weapon";

                if (Input.GetButtonDown("Interact"))
                {
                    weaponHolderManager.UnlockWeapon(weapon._name);
                    Destroy(objectToDescribe);
                    DisableWindow();
                    //Debug.Log("Premuto il tasto e 2");
                }
            }
        }
    }
예제 #2
0
    private void OnCollisionEnter(Collision other)
    {
        // se si collide con il player
        if (other.transform.CompareTag("Player"))
        {
            // se e' presente un componente di tipo FPSController
            if (other.transform.GetComponent <FPSController>() != null)
            {
                // assegno la variabile
                fpsController = other.transform.GetComponent <FPSController>();

                // se il gameobject a cui e' attaccato lo script contiene un componente di tipo WeaponProps
                if (GetComponent <WeaponProps>() != null)
                {
                    // assegno la variabile
                    weapon = GetComponent <WeaponProps>();

                    // se l'arma e' la granata utilizzo il suo metodo per ricaricare
                    if (weapon._name == "Granade")
                    {
                        ExplosiveLauncher granadeHolderManager = other.transform.GetComponent <FPSController>().granadeHolder.GetComponent <ExplosiveLauncher>();

                        if (!granadeHolderManager.IsWeaponFull(weapon._name))
                        {
                            // ricarica la granata
                            granadeHolderManager.RefillAmmoToWeapon(weapon._name, weapon._currentChargerAmmo);
                            // distruggi l'oggetto
                            Destroy(gameObject);
                        }
                    }
                    // se l'arma e' un'arma generica utilizzo il metodo generico per la ricarica
                    else
                    {
                        WeaponHolderManager weaponHolderManager = other.transform.GetComponent <FPSController>().weaponHolder.GetComponent <WeaponHolderManager>();

                        if (weaponHolderManager.IsUnlocked(weapon._name) && !weaponHolderManager.IsWeaponFull(weapon._name))
                        {
                            // ricarica l'arma
                            weaponHolderManager.RefillAmmoToWeapon(weapon._name, weapon._currentChargerAmmo);
                            // distruggi l'oggetto
                            Destroy(gameObject);
                        }
                    }
                }
            }
        }
    }