unity实现前后左右移动代码_Unity3d如何⽤按钮控制物体前后
左右移动?
public var target:Transform;
public var moveSpeed=1;
function Start(){
if(!target){
print("not set target!");
var go=GameObject.CreatePrimitive( PrimitiveType.Cube);
ansform;
target.position=ansform.TransformPoint(Vector3(0,0,5));
}
}
function OnGUI(){
var width=60;
var height=20;
GUI.BeginGroup(Rect((Screen.width-width*2)/2,Screen.height-height*3,width*2,height*3));
var ;
if(GUI.Button(Rect(width/2,0,width,height),"forward")){
moveDirection.z=1;
}
if(GUI.Button(Rect(width/2,height*2,width,height),"back")){
moveDirection.z=-1;
}
if(GUI.Button(Rect(0,height,width,height),"left")){
moveDirection.x=-1;
}
if(GUI.Button(Rect(width,height,width,height),"right")){
moveDirection.x=1;
}
if(target){
moveDirection=moveDirection*moveSpeed;
target.position=target.position+ ation*moveDirection;
左右3d怎么看
}
GUI.EndGroup(); }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论