Example #1
0
    // Check for collisions with the button
    void OnCollisionEnter(Collision collision)
    {
        ContactPoint contact = collision.contacts[0];

        GameObject other = contact.otherCollider.gameObject;

        // Debug.Log("a collision has happened between "+contact.thisCollider.name +" and "+other.name+" impulse was "+collision.impulse.magnitude);
        // I added the collision detection with the boxes, as it could happen that a box is placed in between of the
        // player and the button...So if the bot now pushed the box towards the button, the button is pressed.
        // You can remove this feature if you wish of course.
        if (other.tag == "Player" || other.tag == "Box" && collision.impulse.magnitude > 10 && pressed == false)
        {
            // Debug.Log("a collision has happened between " + contact.thisCollider.name + " and " + other.name);

            pressed = true;

            PitRaycaster.GetComponent <BoxCollider>().enabled = true;

            //--depress the button
            this.gameObject.transform.localPosition = pushedPos;
            rend.material.color = highlightColor;

            //--restore button after 15 seconds
            Invoke("MyWaitingFunction", 15);
        }
    }
Example #2
0
 void MyWaitingFunction()
 {
     // reset button to initial position
     this.gameObject.transform.position = startPos;
     pressed = false;
     PitRaycaster.GetComponent <BoxCollider>().enabled = false;
     rend.material.color = initialColor;
 }