unity怎么让事件过一段时间后执行(语言-c#)

比如说我控制角色在游戏中打开了一个开关 我希望这个开关在三秒钟后自动关上 C#中该怎么实现

可以用到协程。
例:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Test : MonoBehaviour, IPointerClickHandler
{

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("点击了物体" + name);
        StartCoroutine(SetActiveFalse());
    }


    IEnumerator SetActiveFalse()
    {
        yield return new WaitForSeconds(3);
        gameObject.SetActive(false);
    }
}

最简单的是使用延迟函数Invoke()