【发布时间】:2020-12-15 17:13:32
【问题描述】:
我有一个 Sprite Player,它通过以下代码移动
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
public Transform player;
[SerializeField]
private float speed = 10f;
void OnMouseDrag()
{
if (!Player.lose) {
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.x = mousePos.x > 4.0f ? 4.0f : mousePos.x;
mousePos.x = mousePos.x < -0.38f ? -0.38f : mousePos.x;
player.position = Vector2.MoveTowards(player.position,
new Vector2(mousePos.x, player.position.y),
speed * Time.deltaTime);
}
}
}
这两行用于锁定玩家向两侧的移动。
mousePos.x = mousePos.x > 4.0f ? 4.0f : mousePos.x;
mousePos.x = mousePos.x < -0.38f ? -0.38f : mousePos.x;
如果 Players Sprite 进入左侧屏幕边框,我该怎么做,它从右侧出现,相反
【问题讨论】: