public override void Fire(float rotation) { Globals.audioManager.PlayGameSound("pistol"); PistolBullet b = Globals.gameInstance.projectileManager.pistolBulletPool.Provide(); b.Construct(emmitterPosition, rotation); base.Fire(rotation); }
public void Produce(Player santa) { Bullet bullet = new PistolBullet(santa.LastDirection); bullet.PositionX = (int)santa.Position.X + santa.CollisionBox.Width / 2; bullet.PositionY = (int)santa.Position.Y + santa.CollisionBox.Height / 2; this.bullets.Add(bullet); }
void Update() { if (active)//if gun is picked up by player { //Update UI UI.ammoCapacity = maxClip; UI.ammo = clip; //update mouse position tempVector.x = Input.mousePosition.x; tempVector.y = Input.mousePosition.y; tempVector.z = Mathf.Abs(cam.transform.position.z);//depth of camera mousePos = cam.ScreenToWorldPoint(tempVector); //update gun position tempVector = player.transform.position; tempVector.z = 0; //gun in front of player tempVector.y += -0.4f; //offsets gun higher transform.position = tempVector; //update gun orientation tempVector.x = 0; tempVector.y = 0; tempVector.z = Mathf.Atan2(mousePos.y - transform.position.y, mousePos.x - transform.position.x) * Mathf.Rad2Deg; //angle of gun in degrees scale = transform.localScale; if (Mathf.Abs(tempVector.z) > 90) //if gun is facing other way, flip gun { scale.y = -1 * Mathf.Abs(scale.y); } else { scale.y = Mathf.Abs(scale.y); } transform.localScale = scale; transform.rotation = Quaternion.AngleAxis(tempVector.z, Vector3.forward);//rotate gun //decrement reloading delay reloadingDelay -= Time.deltaTime; //done reloading if (reloadingDelay < 0 && clip == 0) { clip = maxClip; } //fire if (Input.GetMouseButtonDown(0) && reloadingDelay < 0)//if left click clicked (only triggered once if held) and not reloading { audioSource.PlayOneShot(fireSFX, 0.6F); clip--; //decrement clip GameObject g = Instantiate(bullet, transform.position, Quaternion.identity); //instantiate bullet prefab PistolBullet p = g.GetComponent <PistolBullet>(); //cache bullet p.direction = (mousePos - transform.position).normalized; //direction bullet is travelling p.transform.rotation = Quaternion.AngleAxis(tempVector.z, Vector3.forward); //rotate bullet if (clip == 0) //if clip is empty, reload automatically { reload(); } } //manual reload (if not already reloading) if (Input.GetKeyDown("r") && reloadingDelay < 0) { reload(); } } }