vp_FPSCamera.SetWeapon C# (CSharp) Méthode

SetWeapon() public méthode

public SetWeapon ( int i ) : void
i int
Résultat void
    public void SetWeapon(int i)
    {
        if (m_Weapons.Count < 1)
        {
            Debug.LogError("Error: Tried to set weapon with an empty weapon list.");
            return;
        }
        if (i < 0 || i > m_Weapons.Count)
        {
            Debug.LogError("Error: Weapon list does not have a weapon with index: " + i);
            return;
        }

        foreach (Transform t in transform)
        {
            t.gameObject.SetActiveRecursively(false);
        }

        m_CurrentWeaponID = i;

        if (m_CurrentWeaponID > 0)
        {
            m_Weapons[m_CurrentWeaponID - 1].transform.parent.gameObject.SetActiveRecursively(true);
            m_CurrentWeapon = (vp_FPSWeapon)m_Weapons[m_CurrentWeaponID - 1].GetComponentInChildren(typeof(vp_FPSWeapon));
            m_CurrentShooter = (vp_FPSShooter)m_Weapons[m_CurrentWeaponID - 1].GetComponentInChildren(typeof(vp_FPSShooter));

            if (m_CurrentWeapon != null)
            {
                if (m_CurrentWeapon.WeaponCamera != null)
                    m_CurrentWeapon.WeaponCamera.SetActiveRecursively(true);
                if (m_CurrentShooter != null)
                {
                    if (m_CurrentShooter.MuzzleFlash != null)
                        m_CurrentShooter.MuzzleFlash.SetActiveRecursively(true);
                }
                m_CurrentWeapon.SetPivotVisible(false);
            }
        }
    }

Usage Example

Exemple #1
0
    ///////////////////////////////////////////////////////////
    // in 'Start' we do things that potentially depend on all
    // other components first having run their 'Awake' calls
    ///////////////////////////////////////////////////////////
    void Start()
    {
        // set up weapon availability. if a weapon is not in this
        // list the script won't allow the player to use it. all
        // weapons are available by default.
        // NOTE: this is just a placeholder for your game's actual
        // inventory system (as is ammo availability, which is set
        // on every vp_FPSShooter individually)
        foreach (GameObject weapon in Camera.Weapons)
        {
            m_AvailableWeapons.Add(weapon);
        }

        // use the 'SetWeaponAvailable' method to give or take weapons
        // from the player, and check 'WeaponAvailable' to see if the player
        // has a certain weapon. all weapons can be taken away by doing:
        // 'm_AvailableWeapons.Clear();'

        // attempt to set weapon 1
        if (WeaponCount > 0)
        {
            Camera.SetWeapon(1);
        }
    }
All Usage Examples Of vp_FPSCamera::SetWeapon