Unity3D项目

Input.mousePosition //鼠标点击的位置

0 左键  1右键  2滚轮

Input.GetMouseButton(0) //当鼠标左键处于按下状态的时候返回True

Input.GetMouseButtonUp(0)//当鼠标左键抬起的时候返回true

Input.GetMouseButtonDown(0)//当鼠标左键按下的时候返回true

Input.GetAxis("Mouse X")  //在水平移动距离

Input.GetAxis("Mouse Y")  //在垂直移动距离

跟着鼠标 旋转

float x1=Input.mousePosition.x-xZero;

float y1=Input.mousePosition.y-yZero;

float angle=90f;

if(y1!=0)

{

  angle=Mathf.Atan(x1/y1);

  angle=180*angle/Mathf.PI;

}

if(y1<0)

{

     angle+=180;

}

transform.localRotation=Quaterniton.AngleAxis(angle,Vector3.up);

Alpha0  表示数字0;

通过按键 控制英雄向左右走

if(Input.GetKey(KeyCode.W))

{

  if(Input.GetKey(KeyCode.LeftShift))

  {

      animation.Play("Run");

      speed=3f;
  }
 else

  {

    animation.Play("Walk");

    speed=1f;

  }

  transform.Translate(Vector3.forward*speed*Time.deltaTime);

}

else

{

  animation.Play("Idle");

}

transform.Translate(Vector3.forward*Input.GetAxis("Horizontal"))

 

posted @ 2015-07-23 11:24  我_爱编程  阅读(210)  评论(0编辑  收藏  举报