// Update is called once per frame void Update() { if (playerState.IsShooting()) { GameObject bulletInstance = null; if (playerState.IsMissleOn() && (playerInventory.HasNumMissles() || playerInventory.missleCount.text == "99")) { if (playerInventory.missleCount.text != "99") { playerInventory.subtractMissles(); } bulletInstance = GameObject.Instantiate(misslePrefab); } else if (playerInventory.HasLongShot() && !playerState.IsMissleOn()) { bulletInstance = GameObject.Instantiate(longBulletPrefab); } else if (!playerState.IsMissleOn()) { bulletInstance = GameObject.Instantiate(bulletPrefab); } if (playerState.IsLookingUp()) { bulletInstance.transform.Rotate(Vector3.forward * 90); bulletInstance.transform.position = firingPositionUpward.position; bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.up * firingSpeed; } else { bulletInstance.transform.position = firingPositionForward.position; if (playerDirection.IsFacingRight()) { bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.right * firingSpeed; } else { bulletInstance.GetComponent <SpriteRenderer>().flipX = true; bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.left * firingSpeed; } } } }
void Update() { if (Input.GetKeyDown(KeyCode.X)) { GameObject bulletInstance = GameObject.Instantiate(bulletPrefab); bulletInstance.name = "Bullet"; bool lookUp = playerDirection.IsLookingUp(); bool faceRight = playerDirection.IsFacingRight(); if (lookUp) { bulletInstance.transform.position = firingPositionUpward.position; bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.up * firingSpeed; } else { bulletInstance.transform.position = firingPositionForward.position; if (faceRight) { bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.right * firingSpeed; } else { bulletInstance.GetComponent <Rigidbody>().velocity = Vector3.left * firingSpeed; } } } if (ExistBullet()) { StandAnimator?.SetBool("IsFiring", true); } else { StandAnimator?.SetBool("IsFiring", false); } }