在我的 Unity 游戏中,当鼠标经过它时,我必须在网格中的单元格上方生成一个精灵。我尝试过使用 OnMouseOver 方法和 BoxCollider2D,但它不起作用。
这是我当前的 Cell GameObject 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
[RequireComponent(typeof(BoxCollider2D))]
public class CellManager : MonoBehaviour
{
void OnMouseEnter()
{
//Code (that doesn't execute)
}
void OnMouseExit()
{
//Code
}
}
我学到了很多关于它的知识,我尝试使用EventTrigger并在输入系统(项目设置)上设置“两者”,得到相同的结果。我听说过光线投射和其他东西,但我对此一无所知,也不知道我到底要做什么。