- Home /
How do I stop a timer with OnTriggerEnter()?
Hi, I am still new to Unity and have ran into a problem. I am trying to use onTriggerEnter so that the timer could stop once all the blocks have entered a certain area. The blocks have colliders and rigidbodies. I made a script for the onTriggerEnter to be on the area.
Code: using System.Collections; using UnityEngine; public class WinBox : MonoBehaviour { private int count; [SerializeField] Timer timerObj; //to get functions from different script
void Start()
{
count = 0;
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Block")
{
count++;
}
if (count == 16) //number of blocks to be moved
{
timerObj.Finish();//to end the timer
}
}
}
I mimicked your code in a new project and got the correct results. Could you post the code about how you actually end the timer (Timer.Finish())?
Your answer
Follow this Question
Related Questions
OnTriggerEnter not working, tried everything! :( (C#) 3 Answers
My rigidbody is floating away, its a child of a parent 0 Answers
Collision Detection without a RigidBody 2 Answers
OnTriggerExit happens too soon! 1 Answer
Child calling parent's OnTriggerEnter when no Rigidbody is attached to child 1 Answer