Home > Net >  On Trigger enter Unity VR function
On Trigger enter Unity VR function

Time:08-17

So me and some people are developing a VR game and we need to have it when the VR hand Presses the button Some objects are hidden so when the trigger on the collider is entered

So I have the function

public void update()
{
//Called once per frame
}
Private void Ontriggerenter(collider, other)
{
    if ( other.tag == "Hand")
{
    Copper.SetActive(false);
}

Where copper is a public game object

I still have the start and update functions not sure if that's the problem but the button clicks but the function is never triggered dose someone maybe know the problem

CodePudding user response:

the "T" and "E" of OnTriggerEnter should be capitalized and OnTriggerEnter takes a variableof type Collider. I am not sure if you have configured the colliders correctly. Here is how the code should look like

Private void OnTriggerEnter(collider other)
{
    if ( other.tag == "Hand")
    {
       Copper.SetActive(false);
    }
}

You can check out this article on Unity Collision basics to get some basic idea.

CodePudding user response:

In order for a Trigger collision to happen, both objects need to have colliders, at least one needs to have a non-kinematic Rigidbody component on the same object as the collider, at least one of the colliders needs to have the "IsTrigger" property set to true (checked).

Here is a link to a Chart about how to get different types of collisions.

Note that there is a difference between a Trigger and a Collision (OnTriggerEnter vs OnCollisionEnter).

  • Related