可以使用Screen.widthScreen.height来获取屏幕的宽度和高度,然后使用这两个值除以2来计算屏幕的中心位置。

以下是一个示例代码:

using UnityEngine;

public class ScreenCenter : MonoBehaviour
{
    void Start()
    {
        float centerX = Screen.width / 2f;
        float centerY = Screen.height / 2f;

        Debug.Log("Screen Center: (" + centerX + ", " + centerY + ")");
    }
}

这个代码片段将在控制台输出屏幕的中心位置的坐标。

unity获取屏幕中心位置

原文地址: https://www.cveoy.top/t/topic/jf3a 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录