백지부터 시작하는 이세계 코딩 생활
ScreenToWorldPoint 본문
ScreenToWorldPoint
카메라(Camera)가 비추고 있는 화면(Screen)내의 좌표값을 사용할 수 있게 해준다.
using UnityEngine;
public class TEST : MonoBehaviour
{
private Camera cam;
private void Start()
{
cam = GameObject.Find("Main Camera").GetComponent<Camera>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 posMouse = cam.ScreenToWorldPoint(Input.mousePosition);
transform.position = posMouse;
print(posMouse);
}
}
}
Ref.
1 chameleonstudio.tistory.com/66
2 docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글
OnCollision(...), OnTrigger(...) (0) | 2021.01.13 |
---|---|
LineRenderer (0) | 2021.01.12 |
Invoke, InvokeRepeating (0) | 2021.01.11 |
CompareTag 비교 (0) | 2021.01.11 |
Preserve Aspect (0) | 2021.01.05 |
Comments