我目前正在开发一款多人射击游戏。基本上 atm 你扮演一个立方体,你的手(红色方块)跟随光标进入游戏。
我想将光标移动限制为围绕我的播放器精灵的完美圆圈。
请参阅附图以进行说明。
以下脚本附在“手”(红色方块)上。
public class Handscript : MonoBehaviour
{
void Update()
{
Cursor.visible = false;
Vector3 a = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
a.Set(a.x, a.y, transform.position.z);
transform.position = Vector3.Lerp(transform.position, a, 1f);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想限制光标在我的半径内移动,这是一个附加到我的 Player 预制件的公共变换,如下所示:
//Hand radius
public float radius;
public Transform centerRadius;
Run Code Online (Sandbox Code Playgroud)
我很难被困住并且对整体编码不熟悉,我可以朝正确的方向推动。
如果我不清楚,这里会问基本相同的问题:https : //answers.unity.com/questions/1439356/limit-mouse-movement-around-player.html
编辑:我的最终目标是拥有与传说中的“疯狂互动”游戏类似的手部动作,可在此处找到:https : //www.newgrounds.com/portal/view/118826
EDIT2:可能无法将光标锁定在半径圆内。是否可以将游戏对象“手”锁定在此半径内?
EDIT3:这是我使用的代码,它的作用就像一个魅力:
using System;
using UnityEngine;
public class Handscript : Photon.MonoBehaviour
{
[SerializeField] private GameObject Player2; //Drag your player game object here for its …Run Code Online (Sandbox Code Playgroud)