为什么我不能在我的游戏对象中引用 Graphic Raycaster?

Why can't I reference Graphic Raycaster in my gameObject?

我正在尝试在我的 Canvas 上获取对 Graphic Raycaster 的引用,以便我可以 enable/disable 它。这就是我正在做的:

shopCanvas.GetComponent<GraphicRaycaster> ().enabled = false;

当我在 monoDevelop 中将鼠标悬停在上面的代码上时,它显示 "The name GraphicRaycaster does not exist in the current context"

当我尝试编译 运行 游戏时,我收到此错误:

error CS0246: The type or namespace name `GraphicRaycaster' could not be found. Are you missing a using directive or an assembly reference?

这是我的设置图片:

只需添加:

using UnityEngine.UI;

到您的 C# 代码文件的开头,编译器会找到 GraphicRaycaster