Programing/unity
유니티,unity,3d 캐릭터 클릭한 방향으로 회전하기
고니의 경제주식
2017. 2. 25. 12:21
반응형
using System.Collections.Generic;
using UnityEngine;
public class Turn : MonoBehaviour {
RaycastHit Hit;
float TurnSpeed;
Quaternion dr;
Vector3 Click;
void Start () {
TurnSpeed = 10f;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0)) {
Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out Hit);
Click = Hit.point;
dr = Quaternion.LookRotation ((Click - transform.position).normalized );
dr.x = 0;
dr.z = 0;
// 캐릭터 기울기 방지
transform.rotation = Quaternion.Slerp (transform.rotation, dr, TurnSpeed *Time.deltaTime);
}
}
}
반응형