Exemple #1
0
    void Start()
    {
        m_PlayerWeaponsManager = FindObjectOfType <PlayerWeaponsManager>();
        //DebugUtility.HandleErrorIfNullFindObject<PlayerWeaponsManager, WeaponHUDManager>(m_PlayerWeaponsManager, this);

        WeaponController activeWeapon = m_PlayerWeaponsManager.GetActiveWeapon();

        if (activeWeapon)
        {
            AddWeapon(activeWeapon, m_PlayerWeaponsManager.activeWeaponIndex);
            ChangeWeapon(activeWeapon);
        }

        m_PlayerWeaponsManager.onAddedWeapon += AddWeapon;
        //m_PlayerWeaponsManager.onRemovedWeapon += RemoveWeapon;
        m_PlayerWeaponsManager.onSwitchedToWeapon += ChangeWeapon;
    }
    void Start()
    {
        foreach (var wpnMgr in GameObject.FindObjectsOfType <PlayerWeaponsManager>())
        {
            if (wpnMgr != null && wpnMgr.isActiveAndEnabled)
            {
                m_WeaponsManager = wpnMgr;
                DebugUtility.HandleErrorIfNullFindObject <PlayerWeaponsManager, CrosshairManager>(m_WeaponsManager, this);

                OnWeaponChanged(m_WeaponsManager.GetActiveWeapon());

                m_WeaponsManager.onSwitchedToWeapon += OnWeaponChanged;

                break;
            }
        }
    }
    void OnPicked(PlayerCharacterController byPlayer)
    {
        PlayerWeaponsManager playerWeaponsManager = byPlayer.GetComponent <PlayerWeaponsManager>();

        if (playerWeaponsManager)
        {
            if (playerWeaponsManager.AddWeapon(weaponPrefab))
            {
                // Handle auto-switching to weapon if no weapons currently
                if (playerWeaponsManager.GetActiveWeapon() == null)
                {
                    playerWeaponsManager.SwitchWeapon(true);
                }

                m_Pickup.PlayPickupFeedback();
            }
        }
    }
Exemple #4
0
        void Update()
        {
            float currenFillRatio = m_Weapon.CurrentAmmoRatio;

            AmmoFillImage.fillAmount = Mathf.Lerp(AmmoFillImage.fillAmount, currenFillRatio,
                                                  Time.deltaTime * AmmoFillMovementSharpness);

            BulletCounter.text = m_Weapon.GetCarriedPhysicalBullets().ToString();

            bool isActiveWeapon = m_Weapon == m_PlayerWeaponsManager.GetActiveWeapon();

            CanvasGroup.alpha = Mathf.Lerp(CanvasGroup.alpha, isActiveWeapon ? 1f : UnselectedOpacity,
                                           Time.deltaTime * 10);
            transform.localScale = Vector3.Lerp(transform.localScale, isActiveWeapon ? Vector3.one : UnselectedScale,
                                                Time.deltaTime * 10);
            ControlKeysRoot.SetActive(!isActiveWeapon);

            FillBarColorChange.UpdateVisual(currenFillRatio);
        }
    // Start is called before the first frame update
    void Start()
    {
        Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Default"), LayerMask.NameToLayer("DontHit"), true);

        _playerCharacterController = GetComponent <PlayerCharacterController>();
        DebugUtility.HandleErrorIfNullGetComponent <PlayerCharacterController, PlayerWeaponsManager>(_playerCharacterController, this, gameObject);

        _playerWeaponsManager = GetComponent <PlayerWeaponsManager>();
        DebugUtility.HandleErrorIfNullGetComponent <PlayerWeaponsManager, PlayerWeaponsManager>(_playerWeaponsManager, this, gameObject);

        _hud = GetComponentInChildren <HUD>();
        DebugUtility.HandleErrorIfNullGetComponent <HUD, PlayerWeaponsManager>(_hud, this, gameObject);

        _weaponController = _playerWeaponsManager.GetActiveWeapon();

        rng = new System.Random();

        numBasicPickups          = 0;
        nonShootingSpeedModifier = 1f;
    }
Exemple #6
0
    void OnPicked(PlayerCharacterController byPlayer)
    {
        Debug.Log($"WeaponPickup OnPicked() weaponName={weaponPrefab.weaponName}");
        PlayerWeaponsManager playerWeaponsManager = byPlayer.GetComponent <PlayerWeaponsManager>();

        if (playerWeaponsManager)
        {
            if (playerWeaponsManager.AddWeapon(weaponPrefab, weaponPrefab.weaponName))
            {
                // Handle auto-switching to weapon if no weapons currently
                if (playerWeaponsManager.GetActiveWeapon() == null)
                {
                    playerWeaponsManager.SwitchWeapon(true);
                }

                m_Pickup.PlayPickupFeedback();

                Destroy(gameObject);
            }
        }
    }
Exemple #7
0
    void OnPicked(PlayerCharacterController byPlayer)
    {
        PlayerWeaponsManager playerWeaponsManager = byPlayer.GetComponent <PlayerWeaponsManager>();

        if (playerWeaponsManager)
        {
            if (playerWeaponsManager.AddWeapon(weaponPrefab))
            {
                // Handle auto-switching to weapon if no weapons currently
                if (playerWeaponsManager.GetActiveWeapon() == null)
                {
                    playerWeaponsManager.SwitchWeapon(true);
                }

                m_Pickup.PlayPickupFeedback();

                TelemetryLogger.LogCollect("Weapon", transform.position, weaponPrefab.weaponName, playerWeaponsManager.GetWeaponsHeldCount());

                Destroy(gameObject);
            }
        }
    }
Exemple #8
0
    void Update()
    {
        float currenFillRatio = m_Weapon.currentAmmoRatio;

        ammoFillImage.fillAmount = Mathf.Lerp(ammoFillImage.fillAmount, currenFillRatio, Time.deltaTime * ammoFillMovementSharpness);

        bool isActiveWeapon = m_Weapon == m_PlayerWeaponsManager.GetActiveWeapon();

        canvasGroup.alpha    = Mathf.Lerp(canvasGroup.alpha, isActiveWeapon ? 1f : unselectedOpacity, Time.deltaTime * 10);
        transform.localScale = Vector3.Lerp(transform.localScale, isActiveWeapon ? Vector3.one : unselectedScale, Time.deltaTime * 10);
        controlKeysRoot.SetActive(!isActiveWeapon);

        FillBarColorChange.UpdateVisual(currenFillRatio);

        if (m_Weapon.ammoType >= 0)
        {
            ammoCountText.text = PlayerPrefs.GetInt("ammo" + m_Weapon.ammoType).ToString();
        }
        else
        {
            ammoCountText.text = "∞".ToString();
        }
    }
Exemple #9
0
    void Update()
    {
        activeWeapon = m_PlayerWeaponsManager.GetActiveWeapon();

        ammoCounter.GetComponent <Image>().fillAmount = activeWeapon.currentAmmoRatio;
    }