孙广东 2015.8.16
目的: 这篇文章的主要目的是为了让您了解有关如果在 unity中滚动 3D 骰子
建设一个棋盘游戏 但因为骰子困扰 ;
这个问题分为两个主要部分:
如何掷骰子。
确定是 1和6之间的随机一个整数面值 (六面临标准骰子)。
如何掷骰子
步骤-1: 将标准骰子模型导入 unity3D。调整Transform ,如图所示,将 刚体添加到它。
步骤 -2: 现在将代码片段添加 到脚本 。
注: 这段代码使您能够使用鼠标触发 ,如果进行适当更改,你可以轻松地变为触摸设备。
if (Input.GetMouseButtonDown (0))
{
//initial click to roll a dice
initPos = Input.mousePosition;
//return x component of dice from screen to view point
initXpose = cam.ScreenToViewportPoint (Input.mousePosition).x;
}
//current position of mouse
Vector3 currentPos = Input.