Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
Method OnTriggerStay2D() works only when player is moving

I made a simple "radiation" field through a trigger but it works only when player in move. Function countes two decimal values. What could be the problem?

decimal radIntensity = 0.001m;

decimal currentDose;

private void OnTriggerStay2D(Collider2D area)
{
     if (area.gameObject.tag == "Player")
     {
         currentDose += radIntensity;
     }

     print($"Current dose: {currentDose} R");
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

In the RigidBody2D component there's an option to disable or enable the sleeping mode.

Try to disable it with the RigidbodySleepMode2D.NeverSleep option.

over 4 years ago · Santiago Trujillo Report

0

Also can use a boolean-flag and OnTriggerEnter2D and OnTriggerExit2D. But never sleeping rigidbody is much better

bool _flag;
private void Update()
    {
        if (_flag)
        {
            currentDose += radIntensity;
        }
        print($"Current dose {currentDose} R");
    }
private void OnTriggerEnter2D(Collider2D area)
    {
        if (area.gameObject.tag == "Player")
        {
            _flag = true;
        }
    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            _flag = !true;
        }

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!