Commit 15bcb18e authored by 18손재민's avatar 18손재민

카메라 회전 일단 구현

parent dba4f6af
fileFormatVersion: 2
guid: f6226b2548447a54486acfc694a44e4d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -276,6 +276,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c7d507df55441f7438f6f059e9d2587c, type: 3}
m_Name:
m_EditorClassIdentifier:
dragSpeed: 10
--- !u!114 &2102809461 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7277015661519863741, guid: 20dee07e28273f049a9093ae4453912f,
......@@ -490,6 +491,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1444571407667829093, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f, type: 3}
--- !u!1001 &5089720519379341084
......
......@@ -4,6 +4,8 @@ using UnityEngine;
public class CameraController : MonoBehaviour
{
Vector3 dragOrigin;
public float dragSpeed;
void CameraMove()
{
......@@ -12,15 +14,40 @@ public class CameraController : MonoBehaviour
transform.position += new Vector3(verticalInput + horizontalInput, 0, verticalInput - horizontalInput);
}
void CameraDrag()
{
if (Input.GetMouseButtonDown(1))
{
dragOrigin = Input.mousePosition;
return;
}
if (!Input.GetMouseButton(1)) return;
float deg = Mathf.Atan2(transform.position.z, transform.position.x);
float dis = Vector3.Distance(Vector3.zero, transform.position - new Vector3(0, transform.position.y, 0));
float dif = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin).x * dragSpeed;
transform.position = new Vector3(Mathf.Cos(deg + dif) * dis, transform.position.y, Mathf.Sin(deg + dif) * dis);
transform.LookAt(new Vector3(0, 0, 0));
dragOrigin = Input.mousePosition;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
CameraMove();
CameraDrag();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment