[PlayerCtrl.cs] - 캐릭터에 부착
public class PlayerCtrl : MonoBehaviour { public float moveSpeed = 10; void Update () { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); transform.Translate(new Vector3(h, 0, v) * moveSpeed * Time.deltaTime); transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0)); } }
[FollowCam.cs] - 카메라에 부착, Target에 캐릭터 부착
public class FollowCam : MonoBehaviour { public Transform Target; public float dist = 5f; public float height = 5f; public float dampTrace = 20f; void LateUpdate() { transform.position = Vector3.Lerp(transform.position , Target.position - (Target.forward * dist) + (Vector3.up * height) , Time.deltaTime * dampTrace); transform.LookAt(Target.position); } }
플레이어 따라다니면서 부드러운 무빙 및 마우스(터치로는 드래그) 회전
'NOTE > SaveSource' 카테고리의 다른 글
[Source Save] TouchCameraMove.cs (0) | 2016.10.31 |
---|---|
[Source Save] InputTouchManager.cs (0) | 2016.10.27 |
[SaveSource] Drag Script (0) | 2016.10.14 |
[SaveSource] Touch Pinch Zoom (0) | 2016.10.14 |
[SaveSource] GyroScope Camera (0) | 2016.10.06 |