物体对象在屏幕中的坐标及鼠标坐标

public class CubeLogic : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var position = gameObject.transform.position;

            var pos = Camera.main.WorldToScreenPoint(position);

            Debug.Log("** 屏幕宽度:" + Screen.width);
            Debug.Log("** 屏幕高度:" + Screen.height);

            Debug.Log("** 屏幕坐标:" + pos);

            var mousePositon = Input.mousePosition;

            Debug.Log("** 点击坐标:" + mousePositon);

        }

        gameObject.transform.Translate(1 * Time.deltaTime, 0, 0);
    }
}
posted @ 2024-07-15 21:10  暖暖De幸福  阅读(2)  评论(0编辑  收藏  举报