Question by
mugen-sosa · Mar 14, 2018 at 04:55 PM ·
ontriggerstay
can OnTriggerStay trigger more than 2 seconds?
Hi everyone, om making a open door script with a collider and staytrigger event, when player walks off, the door gets closed, but i see when player stay on the collider more than 2 seconds, the stay function stop working, this is the code for trigger
void OnTriggerStay2D(Collider2D col)
{
if(col.gameObject.tag =="Player")
{Debug.Log(Time.time);}
if(col.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.Z) && !isUp)
{
Debug.Log("Col");
transform.localPosition = new Vector2(transform.localPosition.x + moveOnX, transform.localPosition.y + moveOnY);
isUp = true;
}
}
void OnTriggerExit2D()
{
if(isUp)
{
transform.localPosition = new Vector2(transform.localPosition.x - moveOnX, transform.localPosition.y - moveOnY);
isUp = false;
}
}
thanks
Comment
Best Answer
Answer by meat5000 · Mar 14, 2018 at 05:00 PM
Perhaps your Rigidbody is going to sleep.
Place a Debug.Log inside your OnTriggerExit() to see if its being ended.
thank you that was the problem, i think is not the way but i put never sleep mode on rigidbody
Your answer
Follow this Question
Related Questions
How to write an overlap sphere 2D 0 Answers
Detecting an object inside a trigger 2 Answers
How to change settings OnTrigger 1 Answer
Kinda area damage but with sword 1 Answer
Cant disable bool 3 Answers