- Home /
Input locks Up - Game Ignores Input.
So, Im making a flight/shooter game. When you hit space (Input.GetButton()) it calls my Weapons script, which fires a bullet via Invoke(), which creates a newly instantiated bullet.
However, if I hold down space long enough or hit it enough times, the game lags breifly, then stops responding to input all together. Nothing. No arrow keys, no space, no A or D. Ziltch.
How did I break Unity this time?
Answer by testure · Jul 02, 2011 at 05:32 PM
I'd need to see the input code to be sure, but it's theoretically possible to overrun your input buffer.. especially if you have GetButton calling Invoke inside a loop or something.
Answer by Utman88 · Jul 02, 2011 at 05:43 PM
Inside my PlayerController Script:
void Update ()
{
if(playerVariables.CurrentHitPoints <= 0)
{
Destroy(this);
}
ActionInput();
}
void ActionInput()
{
if(Input.GetButton("Fire1"))
{
foreach (Weapon w in PrimaryWeapons)
{
w.FireWeapon();
}
}
if (Input.GetButton("Fire2"))
{
foreach (Weapon w in SecondaryWeapons)
{
w.FireWeapon();
}
}
}
And my Weapon script:
public void FireWeapon() { if(!IsInvoking("FireShot")) { Invoke("FireShot", Delay); } }
void FireShot()
{
instantiatedBullet = (GameObject)Instantiate(Bullet, transform.position, transform.rotation * bulletRotation);
instantiatedBullet.rigidbody.velocity = transform.root.rigidbody.velocity +
transform.TransformDirection(Vector3.forward * BulletSpeed);
print("Bullet Speed = " + instantiatedBullet.rigidbody.velocity.ToString());
} </pre>