private void HandleShootPrimaryWeapon() { if (input.IsRegularFirePressed() && !PrimaryWeaponCharging && !SpecialWeaponCharging && PrimaryAmmo > 0) { PrimaryWeaponCharging = true; SpeedPrimaryWeapon = 10f; } if (PrimaryWeaponCharging) { CrossHair.enabled = true; CrossHair.startWidth = 0.1f; CrossHair.endWidth = 0.6f; // HACK this is only needed because assets are f*****g flipped Vector3 shootingDirectionAbsolute = new Vector3(Math.Abs(ShootingDirection.x) * -1, ShootingDirection.y, 0); Vector3 ch = (shootingDirectionAbsolute * (SpeedPrimaryWeapon / PrimaryWeapon.MaxSpeed) * 0.6f * 10); // vector for crosshair ch.z = 1; CrossHair.SetPositions(new Vector3[] { Vector3.zero, ch }); var maxSpeed = PrimaryWeapon.MaxSpeed; if (SpeedPrimaryWeapon != maxSpeed) { SpeedPrimaryWeapon += Time.deltaTime * PrimaryWeapon.SpeedStep; // apply charging animation var width = SpeedPrimaryWeapon / maxSpeed * 0.6f; SpriteCharge.size = new Vector2(width, SpriteCharge.size.y); if (SpeedPrimaryWeapon > maxSpeed) { SpeedPrimaryWeapon = maxSpeed; } } } else { CrossHair.enabled = false; } if (input.IsRegularFireReleased() && PrimaryWeaponCharging) { PrimaryWeaponCharging = false; SpriteCharge.size = new Vector2(0, SpriteCharge.size.y); // throw primary weapon var throwable = Instantiate(PrimaryWeapon); throwable.gameObject.transform.position = Position.position + ThrowOffset; throwable.Thrower = Player; throwable.SetSpeed(ShootingDirection, SpeedPrimaryWeapon); animator.Play("throw"); SoundManager.instance.playThrowIt(); CrossHair.SetPositions(new Vector3[] { Vector3.zero }); --PrimaryAmmo; } }