我的游戏中有类似的东西:
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
}
查找播放器是否在窗口中。 我希望它将玩家移动到特定的坐标。 那么什么会将玩家传送到那些坐标?
答案 0 :(得分:1)
尝试以下代码
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
float targetX = 100; // replace it with your value
float targetY = 100; // replace it with your value
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(targetX, targetY, camera.nearClipPlane));
}