unity 如何实现鼠标点击控制角色行走 要代码 javascript的
展开全部
var hit:RaycastHit;
function Update () {
if(Input.GetButtonDown("Fire1")){
var ray:Ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,hit,100)){
}
}
if(hit.point!=Vector3(0,0,0)&&Vector3.Distance(hit.point,Vector3(transform.position.x,0,transform.position.z))>1.0){
turn(Vector3(hit.point.x,transform.position.y,hit.point.z));
move();
}
print(Vector3.Distance(hit.point,transform.position));
}
function turn(look:Vector3){
var targetRotation=Quaternion.LookRotation(look-transform.position,Vector3.up);
transform.rotation=Quaternion.Slerp(transform.rotation,targetRotation,Time.deltaTime*5.0);
}
function move(){
transform.Translate(Vector3.forward*Time.deltaTime*3.8);
}
function Update () {
if(Input.GetButtonDown("Fire1")){
var ray:Ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,hit,100)){
}
}
if(hit.point!=Vector3(0,0,0)&&Vector3.Distance(hit.point,Vector3(transform.position.x,0,transform.position.z))>1.0){
turn(Vector3(hit.point.x,transform.position.y,hit.point.z));
move();
}
print(Vector3.Distance(hit.point,transform.position));
}
function turn(look:Vector3){
var targetRotation=Quaternion.LookRotation(look-transform.position,Vector3.up);
transform.rotation=Quaternion.Slerp(transform.rotation,targetRotation,Time.deltaTime*5.0);
}
function move(){
transform.Translate(Vector3.forward*Time.deltaTime*3.8);
}
追问
ok !!!!!!!good
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询