Example #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            FindObjectOfType <PlayerDeathHandler>().KillPlayer("death_trainjump");
        }
        else if (other.tag == "Bomb")
        {
            PlayerViveController.GetControllerThatHolds(other.gameObject)?.DetachCurrentObject(false);

            other.gameObject.GetComponent <Bomb>().ThrownOut();
            PushObjectAway(other.gameObject);
        }
        else if (other.tag == "Doll")
        {
            PlayerViveController.GetControllerThatHolds(other.gameObject)?.DetachCurrentObject(false);

            other.gameObject.GetComponent <Doll>().OnThrownOut();
            PushObjectAway(other.gameObject);
        }
        else if (other.gameObject.GetComponent <Rigidbody>() != null && other.gameObject.GetComponent <IInteractable>() != null)
        {
            PlayerViveController.GetControllerThatHolds(other.gameObject)?.DetachCurrentObject(false);
            PushObjectAway(other.gameObject);
        }
    }
Example #2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "SawBlade")
        {
            var saw        = other.GetComponentInParent <SawBlade>();
            var isSpinning = saw?.IsSpinning();
            if (!isSpinning.Value)
            {
                return;
            }

            OpenCompartment(false);
            GetComponent <AudioPlayer>().Play("openlock");
            GetComponent <CapsuleCollider>().enabled = false;

            saw.SawUnLock();
        }
        else if (other.tag == "SmallKey")
        {
            GameObject key = other.gameObject;

            // Play lock key sound.
            GetComponent <AudioPlayer>().Play("openlock");

            OpenCompartment();

            PlayerViveController.GetControllerThatHolds(other.gameObject).DetachCurrentObject(false);

            Destroy(other.gameObject);

            GetComponent <CapsuleCollider>().enabled = false;
        }
    }
Example #3
0
    private IEnumerator NewspaperBurnEffect()
    {
        while (burnOutTime >= Time.time)
        {
            paperTextureColor.r -= 0.004f;
            paperTextureColor.b -= 0.004f;
            paperTextureColor.g -= 0.004f;
            paperMaterial.color  = paperTextureColor;
            yield return(new WaitForSeconds(0.1f));
        }

        burningAudio.Stop();
        Instantiate(burnoutParticle, transform.position, transform.rotation, null);
        PlayerViveController.GetControllerThatHolds(gameObject)?.DetachCurrentObject(false);
        Destroy(gameObject);
    }
    public void InsertHandle(EmergencyDoorHandle handle)
    {
        var controller = PlayerViveController.GetControllerThatHolds(handle.gameObject);

        if (controller != null)
        {
            controller.DetachCurrentObject(false);
        }

        handle.SetHolder(this);

        handle.GetComponent <Rigidbody>().useGravity  = false;
        handle.GetComponent <Rigidbody>().isKinematic = true;

        handle.transform.position = transform.position;
        handle.transform.rotation = transform.rotation;

        GetComponent <AudioPlayer>().Play("handleclicked");

        handle.inserted = true;
    }
Example #5
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "GlassFragment")
        {
            var controller = PlayerViveController.GetControllerThatHolds(other.gameObject);

            // Check if player is holding the glass and a piece hasn't just randomly landed on the wire collider
            if (controller != null && controller.gameObject.GetComponent <SteamVR_Behaviour_Pose>().GetVelocity().magnitude >= heldCutForce)
            {
                WireCut();
            }
        }
        else if (other.tag == "SawBlade" && other.GetComponentInParent <SawBlade>().IsSpinning())
        {
            WireCut();
        }
        else if (other.tag == "Scissors")
        {
            WireCut();
        }
    }
Example #6
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Extinguisher" || other.tag == "BaseballBat" || other.tag == "BowlingBall")
        {
            var controller = PlayerViveController.GetControllerThatHolds(other.gameObject);

            if (controller == null)
            {
                if (other.gameObject.GetComponent <Rigidbody>().velocity.magnitude >= thrownBreakForce)
                {
                    BreakGlass();
                }
            }
            else
            {
                if (controller.gameObject.GetComponent <SteamVR_Behaviour_Pose>().GetVelocity().magnitude >= heldBreakForce)
                {
                    BreakGlass();
                }
            }
        }
    }
Example #7
0
    private void OnCollisionEnter(Collision collision)
    {
        if (transform.gameObject.name == "polySurface3157")
        {
            if (!sawBlade.IsSpinning())
            {
                return;
            }
            if (collision.gameObject.tag == "Band")
            {
                newHandleObjects         = new List <GameObject>();
                collision.gameObject.tag = "Untagged";
                originalHandleParent     = collision.gameObject.transform.parent.gameObject;
                grabHandle = collision.transform.GetChild(0).gameObject;
                ContactPoint contact = collision.contacts[0];
                newHandleObjects.AddRange(CutMesh(collision.gameObject, contact.point, transform.right, collision.gameObject.GetComponent <Renderer>().material, true));
                for (int i = 0; i < newHandleObjects.Count; ++i)
                {
                    newHandleObjects[i].gameObject.tag   = "Untagged";
                    newHandleObjects[i].transform.parent = originalHandleParent.transform.root;
                    Destroy(newHandleObjects[i].GetComponent <MeshCollider>());
                    newHandleObjects[i].AddComponent <BoxCollider>();
                }

                RaycastHit hit;
                Physics.Raycast(originalHandleParent.transform.position, Vector3.down, out hit);
                UpperPart = hit.collider.gameObject.name;


                if (UpperPart == newHandleObjects[0].name)
                {
                    newHandleObjects[0].transform.parent = originalHandleParent.transform;
                }


                else
                {
                    newHandleObjects[0].layer = LayerMask.NameToLayer("Default");
                    newHandleObjects[0].AddComponent <Rigidbody>();
                    grabHandle.GetComponent <ConfigurableJoint>().connectedBody = newHandleObjects[0].GetComponent <Rigidbody>();
                    grabHandle.transform.parent = newHandleObjects[0].transform;
                    grabHandle.AddComponent <Ball>();
                    Destroy(newHandleObjects[0].GetComponent <ConfigurableJoint>());
                }


                if (UpperPart == newHandleObjects[1].name)
                {
                    newHandleObjects[1].transform.parent = originalHandleParent.transform;
                }

                else
                {
                    newHandleObjects[1].layer = LayerMask.NameToLayer("Default");
                    newHandleObjects[1].AddComponent <Rigidbody>();
                    grabHandle.GetComponent <ConfigurableJoint>().connectedBody = newHandleObjects[1].GetComponent <Rigidbody>();
                    grabHandle.transform.parent = newHandleObjects[1].transform;
                    grabHandle.AddComponent <Ball>();
                    Destroy(newHandleObjects[1].GetComponent <ConfigurableJoint>());
                }
            }
        }

        else if (transform.gameObject.tag == "GlassFragment")
        {
            var controller = PlayerViveController.GetControllerThatHolds(transform.gameObject);

            // Check if player is holding the glass and a piece hasn't just randomly landed on the wire collider
            if (controller != null && controller.gameObject.GetComponent <SteamVR_Behaviour_Pose>().GetVelocity().magnitude >= heldCutForce)
            {
                if (collision.gameObject.tag == "Wire")
                {
                    collision.gameObject.tag = "Untagged";
                    ContactPoint contact = collision.contacts[0];
                    newHandleObjects.AddRange(CutMesh(collision.gameObject, contact.point, transform.right, collision.gameObject.GetComponent <Renderer>().material, false));
                    newHandleObjects[0].tag = "Untagged";
                    newHandleObjects[1].tag = "Untagged";
                }

                else if (collision.gameObject.tag == "Band")
                {
                    newHandleObjects         = new List <GameObject>();
                    collision.gameObject.tag = "Untagged";
                    originalHandleParent     = collision.gameObject.transform.parent.gameObject;
                    grabHandle = collision.transform.GetChild(0).gameObject;
                    ContactPoint contact = collision.contacts[0];
                    newHandleObjects.AddRange(CutMesh(collision.gameObject, contact.point, transform.right, collision.gameObject.GetComponent <Renderer>().material, true));
                    for (int i = 0; i < newHandleObjects.Count; ++i)
                    {
                        newHandleObjects[i].gameObject.tag   = "Untagged";
                        newHandleObjects[i].transform.parent = originalHandleParent.transform.root;
                        Destroy(newHandleObjects[i].GetComponent <MeshCollider>());
                        newHandleObjects[i].AddComponent <BoxCollider>();
                    }

                    RaycastHit hit;
                    Physics.Raycast(originalHandleParent.transform.position, Vector3.down, out hit);
                    UpperPart = hit.collider.gameObject.name;


                    if (UpperPart == newHandleObjects[0].name)
                    {
                        newHandleObjects[0].transform.parent = originalHandleParent.transform;
                    }


                    else
                    {
                        newHandleObjects[0].layer = LayerMask.NameToLayer("Default");
                        newHandleObjects[0].AddComponent <Rigidbody>();
                        grabHandle.GetComponent <ConfigurableJoint>().connectedBody = newHandleObjects[0].GetComponent <Rigidbody>();
                        grabHandle.transform.parent = newHandleObjects[0].transform;
                        grabHandle.AddComponent <Ball>();
                        Destroy(newHandleObjects[0].GetComponent <ConfigurableJoint>());
                    }


                    if (UpperPart == newHandleObjects[1].name)
                    {
                        newHandleObjects[1].transform.parent = originalHandleParent.transform;
                    }

                    else
                    {
                        newHandleObjects[1].layer = LayerMask.NameToLayer("Default");
                        newHandleObjects[1].AddComponent <Rigidbody>();
                        grabHandle.GetComponent <ConfigurableJoint>().connectedBody = newHandleObjects[1].GetComponent <Rigidbody>();
                        grabHandle.transform.parent = newHandleObjects[1].transform;
                        grabHandle.AddComponent <Ball>();
                        Destroy(newHandleObjects[1].GetComponent <ConfigurableJoint>());
                    }
                }
            }
        }
    }