using UnityEngine;

public class TimeStopOnCollision : MonoBehaviour
{
    public int targetLayer; // 目标层级

    void Start()
    {
        // 设置目标层级，假设目标层级是 "TargetLayer"
        targetLayer = LayerMask.NameToLayer("TargetLayer");
    }

    private void OnCollisionEnter(Collision collision)
    {
        // 检查碰撞物体是否在目标层级
        if (collision.gameObject.layer == targetLayer)
        {
            // 停止时间
            Time.timeScale = 0f;
            Debug.Log("Time stopped!");
        }
    }

    // 可以通过其他条件恢复时间流逝
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R)) // 按下 R 键恢复时间
        {
            Time.timeScale = 1f;
            Debug.Log("Time resumed!");
        }
    }
}
