Update() 함수에 추가
if (isMoveState)
{
//Vector3 targetPos = transform.position + hitPosition;
Vector3 dir = hitPosition - transform.position;
Vector3 dirXY = new Vector3(dir.x, dir.y , 0);
//Vector3 targetPos = transform.position + (hitPosition - transform.position);
Vector3 targetPos = transform.position + dirXY;
Vector3 framePos = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
Vector3 moveDir = (framePos - transform.position);// + Physics.gravity; // 땅에서 다닐거면 중력을 넣고, 하늘을 나는 비행기 일때는 뺀다.
cc.Move(moveDir);
Debug.Log("framePos : " + dir.y + " /// " + framePos + " targetPos : " + targetPos);
if (framePos == targetPos)
{
isMoveState = false;
Debug.Log("Stop");
}
}
else
{
}
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 100f))
{
Debug.Log("hit point : " + hitInfo.point);
int l = hitInfo.transform.gameObject.layer;
//if (l == clickLayer)
{
Debug.Log(" hit object : " + hitInfo.collider.name);
hitPosition = hitInfo.point;
isMoveState = true;
}
}
}
}
'프로그래밍 언어 > 프로그래밍' 카테고리의 다른 글
[JAVA] 채팅 서버, 클라이언트 예제 (0) | 2016.10.02 |
---|---|
[JAVA] 스트림 입출력 형식 (0) | 2016.09.30 |
유니티 점프 (0) | 2016.06.08 |
해시 테이블 (hash table) (0) | 2009.01.18 |
트리 (0) | 2009.01.18 |
댓글