【发布时间】:2020-12-05 00:54:39
【问题描述】:
我正在开发一个曲折游戏,如下所示: [1]:https://i.stack.imgur.com/miKmH.jpg [ZigZagGame][1].
目标是让球沿着路径(之字折线)通过,方法是围绕我放置在之字折线另一端的枢轴旋转路径(上、下、左和右),使用鼠标拖。我想限制路径的方向。这是我要实现的代码:`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotationCheminOnDragMouse : MonoBehaviour
{
float speed = 1.2f;
private void OnMouseDrag()
{
float rotx = Input.GetAxis("Mouse X") * speed * Mathf.Deg2Rad;
float roty = Input.GetAxis("Mouse Y") * speed * Mathf.Deg2Rad;
Vector3 backAngle = Vector3.back;
Vector3 leftAngle = Vector3.left;
transform.RotateAround(backAngle, -rotx);
transform.RotateAround(leftAngle, roty);
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
OnMouseDrag();
}
}
}
` 那么我该如何设置这些限制呢?知道我不明白如何在 C# 中管理统一的角度。我希望你能帮我解决这个问题。并提前感谢您的任何回复。
【问题讨论】: