我有这个统一脚本,可以通过拖动棋盘来移动我的国际象棋棋子。所有数字和棋盘都作为游戏对象从资产商店下载。但是,每个人物都有不同的动作。如何在棋盘上的方块上放置变色或灯光?也许,一些RayCast可以在这里使用,但究竟如何呢? 我非常感谢你的帮助!
我的剧本动作剧本:
private Vector3 screenPoint;
private Vector3 offset;
private Vector3 curScreenPoint;
private Vector3 curPosition;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
Cursor.visible = false;
}
void OnMouseDrag()
{
curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
void OnMouseUp()
{
Cursor.visible = true;
}