public void Fire() { //Debug.Log("Projectile: Fire()"); hasLaunched = true; _Sfx.PlaySound(0); if (!invertDirection) { travelDirection = Vector3.right; } else { travelDirection = -Vector3.right; } transform.parent = null; Destroy(gameObject, lifetime); }
private void Update() { // NOTE: to add support to a joystick right stick, store the vector direction of // that stick and add that to all the logic that's being handled by MouseInput // Added here for testing and quickly pausing to create showcasing stuff if (Input.GetKeyDown(KeyCode.Space)) { paused = !paused; if (paused) { Time.timeScale = 0.0001f; } else { Time.timeScale = 1f; } } if (paused) { return; } // simple movement with Translate Vector3 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); transform.Translate(moveInput * Time.deltaTime * moveSpeed); // conditions to determine if the animation should be walking forward, walking backwards or Idle if ((moveInput.x > 0 || moveInput.y > 0) && MouseInput.directionFromPlayerToMouseWorldPos.x > 0) { PlayAnimation("WalkForward"); } else if ((moveInput.x > 0 || moveInput.y > 0) && MouseInput.directionFromPlayerToMouseWorldPos.x < 0) { PlayAnimation("WalkBackwards"); } else if ((moveInput.x < 0 || moveInput.y < 0) && MouseInput.directionFromPlayerToMouseWorldPos.x < 0) { PlayAnimation("WalkForward"); } else if ((moveInput.x < 0 || moveInput.y < 0) && MouseInput.directionFromPlayerToMouseWorldPos.x > 0) { PlayAnimation("WalkBackwards"); } else { PlayAnimation("Idle"); } // conditions to switch between arms and update their behaviours if (MouseInput.directionFromPlayerToMouseWorldPos.x < -0.1f) { // Update all LookAt2Dv1 on leftDirectionLookAt array // needs to be done from this script to avoid snapping movements when // the arm got disabled with a rotation that's opposite to the new rotation when enabled again UpdateLookAtArray(-1); if (leftDirectionShoulder != null) { leftDirectionShoulder.UpdateRotation(); } // bool to do this action once if (isRightDirection) { // invert the hips if (hips != null) { hips.transform.localScale -= Vector3.right * 2; } // actual method to switch the arms ArmsSetActive(-1); // stop this action isRightDirection = false; } } else if (MouseInput.directionFromPlayerToMouseWorldPos.x > 0.1f) { // Update all LookAt2Dv1 on leftDirectionLookAt array // needs to be done from this script to avoid snapping movements when // the arm got disabled with a rotation that's opposite to the new rotation when enabled again UpdateLookAtArray(1); if (rightDirectionShoulder != null) { rightDirectionShoulder.UpdateRotation(); } if (!isRightDirection) { // invert the hips if (hips != null) { hips.transform.localScale += Vector3.right * 2; } // actual method to switch the arms ArmsSetActive(1); // stop this action isRightDirection = true; } } // get mouse input while holding left click if (Input.GetMouseButton(0) && !isCharging) { FireWeapon(); } if (Input.GetKeyDown(KeyCode.Q)) { currentProjectile++; if (currentProjectile > 1) { currentProjectile = 0; } SetWeaponProjectile(currentProjectile); } #region Charged Shot - This should go into the weapon class, but I decided to do it in here for a faster implementation if (Input.GetMouseButtonDown(1)) { CameraShake.Shake(chargeDelay, 0.05f, 1f); isCharging = true; SetActiveChargeParticle(true); if (chargeSFX != null) { chargeSFX.PlaySound(); } } if (Input.GetMouseButton(1) && isCharging && !isCharged) { chargeTime += Time.deltaTime; SetChargePFXScale(chargeTime); if (chargeTime >= chargeDelay) { isCharged = true; isCharging = false; FireWeapon(1); SetChargePFXScale(1f); SetActiveChargeParticle(false); chargeTime = 0.0f; } } if (Input.GetMouseButtonUp(1)) { if (isCharged) { isCharged = false; isCharging = false; } else { CameraShake.Shake(0f, 0f, 0f); isCharging = false; chargeSFX.StopSound(); SetChargePFXScale(1f); chargeTime = 0.0f; } SetActiveChargeParticle(false); } #endregion if (Input.GetKeyDown(KeyCode.Alpha1)) { SetWeaponProperties(0.125f); } if (Input.GetKeyDown(KeyCode.Alpha2)) { SetWeaponProperties(0.05f); } }