본문 바로가기
Unity3D

터치한 위치에 Image 표시하기

by CodeDiver 2013. 10. 10.
마우스 클릭 또는 Touch한 위치에 특정 Object (Prefab)를 생성하는 방법입니다.

// 변수 - prefab 지정 

public GameObject touchImg;     // 그릴 이미지를 Prefab으로 생성해둔 후 Drag & Drop으로 Script변수에 지정
private Vector3 MousePos; 

void Update() {
    if (Input.GetButton("Fire1")) { 
        MousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, - Camera.main.transform.position.z)); 

        Vector3 pos = new Vector3(MousePos.x, MousePos.y, -1.0f); 
        Quaternion quat = new Quaternion(0, 0, 0, 0); 
        GameObject obj = Instantiate(touchImg, pos, quat) as GameObject; 

        Debug.Log (MousePos); 
    }

}


'Unity3D' 카테고리의 다른 글

[Script] Raycast를 이용한 Picking  (0) 2013.10.14
[Script] Audio 재생하기  (0) 2013.10.11
XML Parser Sample Code  (0) 2013.10.11
Child Object의 Component 접근하기  (0) 2013.10.11
Unity3D 공부 중.  (0) 2013.10.03