1.鼠标左键
if(Input.GetMouseButtonDown(0))
{
Debug.Log("press");
GameObject bullet1 = GameObject.Instantiate(bullet,transform.position,transform.rotation);
Rigidbody rgd = bullet1.GetComponent<Rigidbody>();
rgd.velocity = transform.forward * speed;
}
2.键盘上下左右的控制、球初速度的生成
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical"); //键盘上下左右的控制
transform.Translate(new Vector3(h,v,0) * Time.deltaTime * 20);//球初速度的生成
网友评论