0
尝试创建Connect 4类游戏。我让电路板模型的孔与网格对齐,以便我可以轻松地将圆圈放入它们中。Unity - 跟随鼠标对齐网格
问题是我不知道如何在统一时使对象跟着鼠标,同时也捕捉到网格。
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LockToGrid : MonoBehaviour {
public float gridSize;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
SnapToGrid(gameObject);
}
void SnapToGrid(GameObject Object) {
var currentPos = Object.transform.position;
Object.transform.position = new Vector3(Mathf.Round(currentPos.x/gridSize) * gridSize,
currentPos.y,
currentPos.z);
}
}
在行的上方添加一个不可见的目标,如果这是统一的5您可以在不可见的图像检查中使用以查看您的鼠标是否在目标上方,将检查块放在目标中 –