物體物件在螢幕中的座標及滑鼠座標

暖暖De幸福發表於2024-07-15
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);
    }
}

相關文章