//update crosshairs when pointing at enemy
    void UpdateCrosshairPointingAtEnemy(bool force)
    {
        if (m_CrosshairDataDefault.crosshairSprite == null)
        {
            return;
        }

        if ((force || !m_WasPointingAtEnemy) && m_WeaponsManager.isPointingAtEnemy)
        {
            m_CurrentCrosshair    = m_CrosshairDataTarget;
            crosshairImage.sprite = m_CurrentCrosshair.crosshairSprite;
            m_CrosshairRectTransform.sizeDelta = m_CurrentCrosshair.crosshairSize * Vector2.one;
        }
        else if ((force || m_WasPointingAtEnemy) && !m_WeaponsManager.isPointingAtEnemy)
        {
            m_CurrentCrosshair    = m_CrosshairDataDefault;
            crosshairImage.sprite = m_CurrentCrosshair.crosshairSprite;
            m_CrosshairRectTransform.sizeDelta = m_CurrentCrosshair.crosshairSize * Vector2.one;
        }

        crosshairImage.color = Color.Lerp(crosshairImage.color, m_CurrentCrosshair.crosshairColor, Time.deltaTime * crosshairUpdateshrpness);

        m_CrosshairRectTransform.sizeDelta = Mathf.Lerp(m_CrosshairRectTransform.sizeDelta.x,
                                                        m_CurrentCrosshair.crosshairSize, Time.deltaTime * crosshairUpdateshrpness) * Vector2.one;
    }
예제 #2
0
        void OnWeaponChanged(WeaponController newWeapon)
        {
            if (newWeapon)
            {
                CrosshairImage.enabled   = true;
                m_CrosshairDataDefault   = newWeapon.CrosshairDataDefault;
                m_CrosshairDataTarget    = newWeapon.CrosshairDataTargetInSight;
                m_CrosshairRectTransform = CrosshairImage.GetComponent <RectTransform>();
                DebugUtility.HandleErrorIfNullGetComponent <RectTransform, CrosshairManager>(m_CrosshairRectTransform,
                                                                                             this, CrosshairImage.gameObject);
            }
            else
            {
                if (NullCrosshairSprite)
                {
                    CrosshairImage.sprite = NullCrosshairSprite;
                }
                else
                {
                    CrosshairImage.enabled = false;
                }
            }

            UpdateCrosshairPointingAtEnemy(true);
        }