// Start is called before the first frame update void Start() { MatchController.RegisterOnPause(Pause); MatchController.RegisterOnResume(Resume); _startingPosition = _movingTransform.position; ResetPlayer(); //Invert the ratio in order to use multiplication instead of division later on. Faster calculations. _energyToHPRatio = 1.0f / _energyToHPRatio; _weaponsManager = GetComponentInChildren <WeaponsManager>(); if (_weaponsManager == null) { throw new Exception("Error: weapon manager not found in player."); } if (_collisionResolver == null) { throw new Exception("Error: Collision Resolver not found in player!"); } var playerWeapons = new List <WeaponData>(); playerWeapons.Add(new WeaponData() { GloveType = GloveType.Glove, ProjectileType = ProjectileTypeEnum.Physical }); playerWeapons.Add(new WeaponData() { GloveType = GloveType.Glove, ProjectileType = ProjectileTypeEnum.Energy }); _weaponsManager.CreateWeapons(playerWeapons); _currentWeapon = _weaponsManager.GetCurrentWeapon(); InputController.RegisterOnMouseLeftDown(UsePrimaryWeapon); InputController.RegisterOnMouseLeftUp(StopUsingPrimaryWeapon); InputController.RegisterOnMouseRightPressed(SwitchPrimaryWeapon); InputController.RegisterOnTriggerDown(UsePrimaryWeapon); InputController.RegisterOnTriggerUp(StopUsingPrimaryWeapon); InputController.RegisterOnTouchPressed(SwitchPrimaryWeapon); }
void Shoot() { if (weaponsManager.GetCurrentWeapon().fire == FireType.MULTIPLE) { if (Input.GetMouseButton(0) && Time.time > nextTimeToFire) { nextTimeToFire = Time.time + 1 / fireRate; weaponsManager.GetCurrentWeapon().Shoot(); } } else { if (Input.GetMouseButtonDown(0)) { if (weaponsManager.GetCurrentWeapon().CompareTag(Tags.AXE)) { weaponsManager.GetCurrentWeapon().Shoot(); } if (weaponsManager.GetCurrentWeapon().bullet == BulletType.BULLET) { weaponsManager.GetCurrentWeapon().Shoot(); } if (weaponsManager.GetCurrentWeapon().bullet == BulletType.ARROW || weaponsManager.GetCurrentWeapon().bullet == BulletType.SPEAR) { if (isAim) { weaponsManager.GetCurrentWeapon().Shoot(); } } } } }