Example #1
0
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            PlayerData player = other.GetComponent <PlayerData>();

            if (player)
            {
                if (player.m_pressingButton)
                {
                    m_activated = !m_activated;

                    if (m_activated)
                    {
                        m_mat.color = Color.green;
                    }
                    else
                    {
                        m_mat.color = Color.red;
                    }

                    for (int z = 0; z < m_linkedObjects.Length; z++)
                    {
                        ButtonInteraction script = m_linkedObjects[z].GetComponent <ButtonInteraction>();

                        if (script)
                        {
                            script.OnInteract();
                        }
                    }
                }
            }
        }
    }
Example #2
0
    /*private void OnCollisionExit(Collision Other)
     * {
     *  if (Other.gameObject.tag == "Player" || Other.gameObject.tag == "Box")
     *  {
     *      if (m_activated)
     *      {
     *          for (int z = 0; z < m_linkedObjects.Length; z++)
     *          {
     *              ButtonInteraction script = m_linkedObjects[z].GetComponent<ButtonInteraction>();
     *
     *              if (script)
     *              {
     *                  script.OnInteract();
     *              }
     *          }
     *      }
     *
     *      m_activated = false;
     *
     *      m_mat.color = Color.red;
     *  }
     * }*/

    private IEnumerator CheckCollisions()
    {
        while (true)
        {
            if (!m_hadColision)
            {
                if (m_activated)
                {
                    for (int z = 0; z < m_linkedObjects.Length; z++)
                    {
                        ButtonInteraction script = m_linkedObjects[z].GetComponent <ButtonInteraction>();

                        if (script)
                        {
                            script.OnInteract();
                        }
                    }
                }

                m_activated = false;

                m_mat.color = Color.red;
            }

            m_hadColision = false;

            yield return(new WaitForFixedUpdate());
        }
    }
Example #3
0
    private void OnCollisionStay(Collision Other)
    {
        float angle = Vector2.Angle(Other.contacts[0].normal, Vector2.up);


        if (Mathf.Approximately(angle, 180.0f))
        {
            if (Other.gameObject.tag == "Player" || Other.gameObject.tag == "Box")
            {
                m_hadColision = true;

                if (!m_activated)
                {
                    for (int z = 0; z < m_linkedObjects.Length; z++)
                    {
                        ButtonInteraction script = m_linkedObjects[z].GetComponent <ButtonInteraction>();

                        if (script)
                        {
                            script.OnInteract();
                        }
                    }
                }

                m_activated = true;

                m_mat.color = Color.green;
            }
        }
    }
Example #4
0
    void Update()
    {
        m_Timer.Cycle();

        if (m_Timer.m_completed && !m_activated)
        {
            m_activated = true;
            m_mat.color = Color.blue;

            for (int z = 0; z < m_linkedObjects.Length; z++)
            {
                ButtonInteraction script = m_linkedObjects[z].GetComponent <ButtonInteraction>();

                if (script)
                {
                    script.OnInteract();
                }
            }
        }
    }