2 回答
TA贡献1825条经验 获得超6个赞
此函数将要让按钮四处移动的对象,玩家的游戏对象作为参数,以便您可以将新按钮朝向玩家,您希望按钮所处的角度以及半径(按钮与之之间的距离) buttonCenter)。它的输出是按钮在世界空间中的位置。您可以为要添加的每个按钮调用它。
Vector3 positionButton(GameObject buttonCenter, GameObject player, float angle, float radius) {
//get the up and right vectors from the player object so we can orient the buttons
Vector3 up = player.transform.up;
Vector3 right = player.transform.right;
angle = Mathf.Deg2Rad * angle; //convert degrees to radians. radians=degrees * 2pi / 360
//cos(angle) give an x coordinate, on a unit circle centered around 0
//sin(angle) is the y coordinate on the unit circle
//take those values, multiply them by the up and right vectors to orient them to the player,
//multiply by the radius to move them the correct distance from the buttoncenter,
//and add the buttoncenter position so they circle around the correct point
Vector3 buttonPos =buttonCenter.transform.position + (radius * right * Mathf.Cos(angle)) + (radius* up * Mathf.Sin(angle));
return buttonPos;
}
TA贡献1796条经验 获得超4个赞
首先,为每个按钮定义一个原点和距离。有了角度后,您可以应用三角函数,该函数应允许您在给定角度,距离和原点的情况下找到点的坐标。该点将由角度的cos()和sin()定义。
- 2 回答
- 0 关注
- 210 浏览
添加回答
举报