Skip to content

Instantly share code, notes, and snippets.

@ajgutierr3z
Created January 15, 2026 21:06
Show Gist options
  • Select an option

  • Save ajgutierr3z/b451c46dd1aaa4a3b8bfd3a19dfeeffa to your computer and use it in GitHub Desktop.

Select an option

Save ajgutierr3z/b451c46dd1aaa4a3b8bfd3a19dfeeffa to your computer and use it in GitHub Desktop.
Script Base en C# (Sensor de Inactividad)
using UnityEngine;
public class UserInactivitySensor : MonoBehaviour
{
public Transform userTransform; // Arrastra al jugador aquí
public float idleThreshold = 10f; // Segundos para considerar inactividad
public float movementSensitivity = 0.1f; // Rango mínimo de movimiento
private Vector3 lastPosition;
private float idleTimer = 0f;
public bool isUserIdle = false;
void Start()
{
if (userTransform != null) lastPosition = userTransform.position;
}
void Update()
{
// Calculamos la distancia movida desde el último frame
float distanceMoved = Vector3.Distance(userTransform.position, lastPosition);
if (distanceMoved < movementSensitivity)
{
idleTimer += Time.deltaTime;
if (idleTimer >= idleThreshold)
{
isUserIdle = true;
OnUserIdleDetected();
}
}
else
{
// El usuario se movió: resetear todo
idleTimer = 0f;
if (isUserIdle) OnUserActiveDetected();
isUserIdle = false;
lastPosition = userTransform.position;
}
}
void OnUserIdleDetected()
{
// Aquí disparas eventos: atenuar luces, animar NPC, etc.
Debug.Log("IA: Usuario inactivo. Iniciando protocolo de ahorro.");
}
void OnUserActiveDetected()
{
Debug.Log("IA: Usuario activo detectado. Restaurando sistema.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment