- Home /
Weird behaviour with OnTriggerEnter
I am trying to achieve this in VR using HTC Vive. I want to activate/deactivate a canvas when a certain object is collided with a Beam coming from the Vive Controller. I am using VRTK SDK to shoot the Beam.
The activation/deactivation works fine. The problem is when the Beam hits the next object, the canvas of the previously hit object is affected. The code on the Trigger Objects is as follows:
static public int counter = 0;
public GameObject uiCanvas;
static public DateTime time = DateTime.MinValue;
static public DateTime after;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "GameController")
{
Debug.Log(other.tag.ToString());
Debug.Log(other.name);
if (time == DateTime.MinValue)
{
time = DateTime.Now;
}
else
{
after = DateTime.Now;
TimeSpan timespan = after - time;
if (timespan.TotalSeconds > 1)
counter++;
if (counter % 2 == 0)
uiCanvas.SetActive(true);
else
uiCanvas.SetActive(false);
time = DateTime.Now;
}
}
}
![alt text][1]
all objects contain colliders, rigid bodies and are set to triggers. [1]: /storage/temp/115214-image1.jpg
What could be the cause of this issue?
So you have a separate uiCanvas for each object? How do you assign this? In the inspector? Perhaps a screenshot of the inspector and hierarchy will help
@Serinx yes, there is a canvas for each object. I assign them through the Editor. I have attached two images of two images with the inspector
Your answer
Follow this Question
Related Questions
Which setup should I use for spawning? 0 Answers
Detecting inside an area without a collider 1 Answer
How can I disable this collider, when two are present on the gameobject 1 Answer
Rigidbody.SweepTest Hit Trigger Colliders 0 Answers
How do I only let one collider be affected at a time when using OnTriggerEnter? 1 Answer