Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda