Unity 마우스 방향으로 이동
public Camera mainCamera; //메인 카메라
public float maxSpeed; //최대 속도
public float aclrt; //가속도
private float curr_speed; //현재 속도
private void Update () {
if (Input.GetMouseButton (0)) {
Ray ray = mainCamera.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, Mathf.Infinity) {
Vector3 dir = new Vector3 (hit.point.x - transform.position.x, 0f, hit.point.z - transform.position.z); //방향 구하기
curr_speed = Mathf.Clamp (curr_speed += aclrt * Time.deltaTime, 0f, maxSpeed); //가속
transform.rotation = Quaternion.LookRotation (dir); //방향 설정
}
} else {
curr_speed = Mathf.Clamp (curr_speed -= aclrt * Time.deltaTime, 0f, maxSpeed); //감속
}
transform.Translate (Vector3.forward * curr_speed * Time.deltaTime); //
}