Input.GetKeyDown returns true during the frame the user starts pressing down the key identified by name, while Input.GetKey returns true while the user holds down the key identified by name.
Seems you need to give Input.GetKey a try.
To keep it calling while pressed, call it from the Update()
.
public void spawnLaser()
{
GameObject laser = Instantiate(laserprefab, transform.position,
Quaternion.identity) as GameObject;
laser.GetComponent<Rigidbody2D>().velocity = new Vector2(laserSpeed, 0);
}
void Update()
{
if (Input.GetKey("up"))
{
print("up arrow key is held down");
spawnLaser();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…