Пример #1
0
    /// <summary>
    /// Triggers on button released
    /// </summary>
    /// <param name="other"></param>
    void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("PlayerFeet"))
        {
            // Remove them from the list
            if (m_objectedPressingTheButton.Contains(other.gameObject))
            {
                m_objectedPressingTheButton.Remove(other.gameObject);
            }

            if (IsPressed)
            {
                // We will only trigger release when there are no other objects
                // pressing the button (or another of the same type)
                if (m_objectedPressingTheButton.Count > 0)
                {
                    return;
                }

                AudioManager.Instance.PlaySoundAt(AudioClipName.ButtonOff, transform.position);
                IsPressed = false;
                Controllables.ForEach(c => { if (c != null)
                                             {
                                                 c.OnButtonReleased();
                                             }
                                      });
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Triggers on button pressed
    /// </summary>
    /// <param name="other"></param>
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("PlayerFeet"))
        {
            // Trigger press if no other one has been pressed
            if (!IsPressed)
            {
                AudioManager.Instance.PlaySoundAt(AudioClipName.ButtonOn, transform.position);
                IsPressed = true;
                Controllables.ForEach(c => { if (c != null)
                                             {
                                                 c.OnButtonPressed();
                                             }
                                      });
            }

            // Add the new object on the button
            if (!m_objectedPressingTheButton.Contains(other.gameObject))
            {
                m_objectedPressingTheButton.Add(other.gameObject);
            }
        }
    }