您的位置:首页 > 其它

u3d脚本入门二,键盘控制物体上下左右和缩放(原创)

2016-04-24 22:42 176 查看
#pragma strict
var np:GameObject;
function Start () {
  // 动态创建也可以
  //np = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
function Update () {
  if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D)){
    np.transform.localRotation = Quaternion.identity;
    print('dddddddd');
  }
  if(Input.GetKey(KeyCode.A)){
    np.transform.Rotate(0,0,-5);
    //np.transform.Instantiate(np,Vector3(0.3,1,0.5),Quaternion.identity);
  }
  if(Input.GetKey(KeyCode.D)){
    np.transform.Rotate(0,0,5);
  }
  if(Input.GetKey(KeyCode.W)){
    np.transform.Rotate(-5,0,0);
  }
  if(Input.GetKey(KeyCode.S)){
    np.transform.Rotate(5,0,0);
  }
  if(Input.GetKey(KeyCode.Q)){
    np.transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
  }
  if(Input.GetKey(KeyCode.E)){
    np.transform.localScale -= new Vector3(0.1F, 0.1F, 0.1F);
  }
}

转载于:https://my.oschina.net/uvvv/blog/665482

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: