void Update() { if (Input.GetKeyDown(KeyCode.Space)) { } else if (Input.GetKeyDown(KeyCode.RightArrow)) { playerShoot.fire(new Vector2(1f, 0f)); } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { playerShoot.fire(new Vector2(-1f, 0f)); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { playerShoot.fire(new Vector2(0f, 1f)); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { playerShoot.fire(new Vector2(0f, -1f)); } else if (Input.GetKeyDown(KeyCode.Comma)) { bodyShrink.shrink(); } else if (Input.GetKeyDown(KeyCode.Period)) { bodyShrink.expand(); } }
public void fire(Vector2 direction) { var bulletInstance = (GameObject)Instantiate(bulletPrefab, spawnPosition.position, spawnPosition.rotation); bulletInstance.GetComponent <Rigidbody2D>().AddForce(direction * speed, ForceMode2D.Impulse); bodyShrink.shrink(); Destroy(bulletInstance, timeToLive); }