c# - 如何在棋盘上创建曲线(统一的立方体),角色在哪里可以选择走或不走另一条路?基于骰子的运动
问题描述
我正在制作一个棋盘游戏,我创建了 2 个脚本,它运行良好且没有错误,当我按下空格键时,角色会根据 1 到 6 的随机数移动,但我不能让他走在弧形板,我希望角色进行调解,并用箭头或钥匙决定他是否要转身。还想将骰子的精灵与正确的随机数相关联,这是“石头”(角色)的脚本:
public Route currentRoute;
int routePosition;
public int steps;
bool isMoving;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !isMoving)
{
steps = Random.Range(1, 7);
Debug.Log("Dice Rolled " + steps);
StartCoroutine(Move());
// if(routePosition+steps < currentRoute.childNodeList.Count)
// {
// StartCoroutine(Move());
// }
// else
// {
// Debug.Log("Rolled Number is to high");
// }
}
}
IEnumerator Move()
{
if (isMoving)
{
yield break;
}
isMoving = true;
while (steps > 0)
{
routePosition++;
routePosition %= currentRoute.childNodeList.Count;
Vector3 nextPos = currentRoute.childNodeList[routePosition].position;
while (MoveToNextNode(nextPos)) { yield return null; }
yield return new WaitForSeconds(0.1f);
steps--;
//routePosition++;
}
isMoving = false;
}
bool MoveToNextNode(Vector3 goal)
{
return goal != (transform.position = Vector3.MoveTowards(transform.position, goal, 4f * Time.deltaTime));
}
这里是“节点”(“节点”是棋盘上的空间,角色将根据骰子数字继续移动。):
Transform[] childObjects;
public List<Transform> childNodeList = new List<Transform>();
void Start()
{
FillNodes();
}
void OnDrawGizmos()
{
Gizmos.color = Color.green;
FillNodes();
for (int i = 0; i < childNodeList.Count; i++)
{
Vector3 currentPos = childNodeList[i].position;
if (i > 0)
{
Vector3 prevPos = childNodeList[i - 1].position;
Gizmos.DrawLine(prevPos, currentPos);
}
}
}
void FillNodes()
{
childNodeList.Clear();
childObjects = GetComponentsInChildren<Transform>();
foreach (Transform child in childObjects)
{
if (child != this.transform)
{
childNodeList.Add(child);
}
}
}
解决方案
推荐阅读
- antlr - 解析以特定关键字开头和结尾的代码块
- javascript - 是否可以完全用 javascript 构建一个 html 网页?
- c# - 无法在 RavenDB 上查询附件
- performance - 甲骨文商务云首页加载的性能提升
- php - Laravel 8 - 从数据库中计算行数
- python - 通过 Firefox (Python) 保存和重复使用 Selenium 制作的 GMAIL cookie
- reactjs - 删除 url 中的参数以进行 nextjs 重定向
- r - 在 x 轴上制作包含多个变量的深度剖面,包括误差线
- python - Pyspark - 将字符串类型元素数组转换为键值对映射
- kubernetes - Pod 无法访问 kubernets clusterIP 服务 (10.96.0.1)