void Update() { if (currPauseMenuIsOpenState == PauseMenu.I.IsMenuOpen) { return; } currPauseMenuIsOpenState = PauseMenu.I.IsMenuOpen; if (currPauseMenuIsOpenState) { wasPlayingBeforePauseMenuWasOpened = timerTween.IsPlaying(); Pause(); } else { if (wasPlayingBeforePauseMenuWasOpened) { Play(); } else { // Just continue playing the audio if (alarmSfxSource != null) { alarmSfxSource.Play(); } } } }
void UpgradePlanet() { if (CurrentUpgradeLevel == GameController.PlanetTypes[CurrentType].UpgradeLevels.Length - 1) { return; } CurrentUpgradeLevel++; IsUpgrading = false; if (Owner == GameController.Players[0]) { _au.Play(GameController.PlanetUpgradeSound); } UpdateAppearance(); }
public void Update() { if (!shouldPlay) { phase = STOP; } else { if (!source.IsPlaying) { phase = START; source.Position = 0.0f; source.Loop = false; source.Play(); } } if (!source.IsPlaying) { return; } var length = source.Duration; if (phase == LOOP) { source.Loop = true; if (source.Position >= endPerc * length) { source.Position = startPerc * length; } } else { source.Loop = false; if (phase == START) { if (source.Position >= startPerc * length) { phase = LOOP; source.Loop = true; } } else // STOP { if (source.IsPlaying && source.Position < 0.75f * (endPerc * length) && source.Position >= startPerc * length) { source.Position = endPerc * length; } } } }
protected override void Update() { Transform.Rotation = (float)Math.Atan2(_rb.velocity.X, -_rb.velocity.Y); DrawPursuitLine(); if (!Target.Enabled) { Destroy(GameObject); } if (Vector3.Distance(Transform.Position, Target.Transform.Position) <= 5) { Target.Kill(); _au.Play(ShipShotSound); Destroy(GameObject); } }
public void Update(float deltaTime) { var volume = enable ? baseVolume : 0; var pitch = enable ? basePitch * 1.5f : basePitch * 1; float volumeSpeed = enable ? turnOnSpeed : turnOffSpeed; float pitchSpeed = enable ? turnOnSpeed : turnOffSpeed; source.Volume = Mathf.Lerp(source.Volume, volume, volumeSpeed * deltaTime); source.Pitch = Mathf.Lerp(source.Pitch, pitch, pitchSpeed * deltaTime); if (source.Volume < 0.05f && source.IsPlaying) { source.Stop(); } else if (source.Volume > 0.075f && !source.IsPlaying) { source.Play(); } }
private void CheckSongPause() { bool isMenuOpen = UI.PauseMenu.I.IsMenuOpen; if (loopingSource != null && loopingSource.IsPlaying && isMenuOpen) { float currentTime = loopingSource.Position; lastSongTime = currentTime; loopingSource.Pause(); songPaused = true; Debug.Log("SONG PAUSING"); } else if (loopingSource != null && !loopingSource.IsPlaying && !isMenuOpen && songPaused) { loopingSource.Stop(); loopingSource.Play(); loopingSource.Position = lastSongTime; songPaused = false; Debug.Log("SONG RESUMING"); } }
public void Appear() { toggleVisibility(true); isAppearing = true; List <Vector3> trajectoryPoints = new List <Vector3>(); var startPivot = Fruits[0].transform.GetChild(0).gameObject.transform; var finalPosition = startPivot.position + new Vector3(0f, 0.6f, 0f); rocketMoveSFX = MazeConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.RocketMove); rocketMoveSFX.Play(); float duration = 1; if (!MazeGame.instance.isTutorialMode) { duration = 1; trajectoryPoints.Add(-startPivot.right * 15); transform.position = trajectoryPoints[0]; } else { duration = 3; trajectoryPoints.Add(transform.position); int numTrajectoryPoints = 7; float yDecrement = (finalPosition.y - transform.position.y) / (numTrajectoryPoints + 1); float[] trajectoryPointXAnchors = { -0.7f, 0f, 0.7f, 0f, -0.75f, -0.4f, 0f }; float[] trajectoryPointZAnchors = { 0f, 0.8f, 0f, -0.8f, -0.5f, 0.7f, 0.85f, 1.2f }; for (int i = 0; i < numTrajectoryPoints; i++) { Vector3 trajectoryPoint = new Vector3(); trajectoryPoint.y = transform.position.y + (i + 1) * yDecrement; var frustumHeight = GetFrustumHeightAtDistance(Camera.main.transform.position.y - trajectoryPoint.y); var frustumWidth = GetFrustumWidth(frustumHeight); trajectoryPoint.x = frustumWidth * 0.5f * trajectoryPointXAnchors[i]; trajectoryPoint.z = frustumHeight * 0.5f * trajectoryPointZAnchors[i]; trajectoryPoints.Add(trajectoryPoint); } } trajectoryPoints.Add(finalPosition); transform.DOPath(trajectoryPoints.ToArray(), duration, PathType.CatmullRom, PathMode.Ignore).OnWaypointChange((int index) => { if (index + 1 < trajectoryPoints.Count) { LookAt(trajectoryPoints[index + 1], true); } }).OnComplete(() => { toggleVisibility(false); isAppearing = false; rocketMoveSFX.Stop(); //transform.rotation = initialRotation; MazeGame.instance.showCurrentTutorial(); }); }
void Update() { for (int i = 0; i < bars.Count; ++i) { var bar = bars[i]; int completedPairId = (completedBars / 2) * 2; bool show = (i >= completedPairId) && (i < completedPairId + 2); bar.Show(show); } bool isMenuOpen = UI.PauseMenu.I.IsMenuOpen; songInsideAWord = false; if (playingSong) { if (songSource != null && songSource.IsPlaying) { float currentTime = songSource.Position; lastSongTime = currentTime; if (isMenuOpen) { songSource.Pause(); return; } var songWords = currentBarSong.lines; var songStart = songWords[0].start; if (currentTime > songStart - 2) { if (!songStarted && activeBar == null) { SetActiveBar(bars[0]); } songStarted = true; } if (songStarted) { for (int i = 0; i < songWords.Count; ++i) { var currentSongWord = songWords[i]; var currentBarWord = currentBarWords[i]; var timeStart = currentSongWord.start; var timeEnd = currentSongWord.end; // Move to currentBarWord while (activeBar != null && activeBar.Id < currentBarWord.barId) { SwitchToNextBar(); } if (currentTime < timeStart) { if (activeBar != null && activeBar.Id == currentBarWord.barId) { activeBar.currentTarget = 0; } break; } else if (currentTime > timeEnd) { barsCompleted = (i == songWords.Count - 1); if (activeBar != null && activeBar.Id == currentBarWord.barId) { if (i == 3 || i == 7) // only at specific rows // TODO: find a better way to stop the music halfway { ((ReadingGameGame)(ReadingGameGame.I)).hiddenText.gameObject.SetActive(false); bars[0].transform.parent.gameObject.SetActive(false); //KeeperManager.I.PlayDialogue(LocalizationDataId.Song_alphabet_SingWithMe, false, keeperMode:KeeperMode.SubtitlesOnly); } } } else { // Show bar if (!bars[0].transform.parent.gameObject.activeInHierarchy) { ((ReadingGameGame)(ReadingGameGame.I)).hiddenText.gameObject.SetActive(true); bars[0].transform.parent.gameObject.SetActive(true); KeeperManager.I.CloseSubtitles(); } float tInWord = (currentTime - timeStart) / (timeEnd - timeStart); float t = Mathf.Lerp(currentBarWord.start, currentBarWord.end, tInWord); if (activeBar != null) { activeBar.currentTarget = t; } songInsideAWord = true; break; } } } if (barsCompleted) { SetActiveBar(null); } } else if (barsCompleted) { songStarted = false; playingSong = false; songSource = null; if (onSongCompleted != null) { onSongCompleted(); } } else { if (songSource != null && !songSource.IsPlaying && !isMenuOpen) { songSource.Stop(); songSource.Play(); songSource.Position = lastSongTime; } } } }
public override void OnActivate() { _audioSourceWinTransition.Play(); }
protected override void Update() { Planet planet = null; // Detect if there is a planet under the mouse cursor foreach (var p in GameController.Planets) { if (Vector3.Distance(Input.GetMousePosition(), p.Transform.Position) < 30) { planet = p; } } if (planet) { _lastHoveredPlanet = planet; if (planet.Owner == this) { // Show hover if (!_selectedPlanet || (_selectedPlanet != null && _selectedPlanet != planet)) { planet.Hover(); } // Select planet if (Input.GetActionUp("PrimaryAction")) { Debug.Log("Selected planet"); if (_selectedPlanet) { _selectedPlanet.DeSelect(); } UnHover(); _selectedPlanet = planet; _selectedPlanet.Select(); } /*if (_selectedPlanet != null && _selectedPlanet == planet) * { * // Toggle upgrade menu * if (Input.GetActionDown("SecondaryAction")) * { * } * }*/ } if (_selectedPlanet != null && _selectedPlanet != planet) { // Show line _lineRenderer.Start = _selectedPlanet.Transform.Position; _lineRenderer.End = planet.Transform.Position; _lineRenderer.Size = 3; _lineRenderer.Color = new Color(236, 196, 73); if (Input.GetActionDown("SecondaryAction") && _selectedPlanet != null) { Debug.Log("Selected target planet"); _au.Play(AttackCommandSound); _selectedPlanet.LaunchShips(planet, _selectedPercentage); _selectedPlanet.DeSelect(); _selectedPlanet = null; UnHover(); } } } else { UnHover(); if (Input.GetActionUp("PrimaryAction")) { if (_selectedPlanet) { _selectedPlanet.DeSelect(); _selectedPlanet = null; } } } // Upgrade planet if (_selectedPlanet) { if (Input.GetActionDown("UpgradePlanet")) { _selectedPlanet.StartUpgrade(); } else if (Input.GetActionDown("ChangePlanetToColony")) { _selectedPlanet.StartConversion(0); } else if (Input.GetActionDown("ChangePlanetToSentry")) { _selectedPlanet.StartConversion(1); } } if (Input.GetMouseScrollDelta() > 0 || Input.GetActionUp("Fire")) { _selectedPercentage += 0.25f; if (_selectedPercentage > 1) { _selectedPercentage = 1; } UpdateMouseTexture(); } else if (Input.GetMouseScrollDelta() < 0) { _selectedPercentage -= 0.25f; if (_selectedPercentage < 0.25f) { _selectedPercentage = 0.25f; } UpdateMouseTexture(); } }
void Update() { for (int i = 0; i < bars.Count; ++i) { var bar = bars[i]; int completedPairId = (completedBars / 2) * 2; bool show = (i >= completedPairId) && (i < completedPairId + 2); bar.Show(show); } bool isMenuOpen = UI.PauseMenu.I.IsMenuOpen; songInsideAWord = false; if (playingSong) { if (songSource != null && songSource.IsPlaying) { float currentTime = songSource.Position; lastSongTime = currentTime; if (isMenuOpen) { songSource.Pause(); return; } var songWords = currentBarSong.lines; var songStart = songWords[0].start; if (currentTime > songStart - 2) { if (!songStarted && activeBar == null) { SetActiveBar(bars[0]); } songStarted = true; } if (songStarted) { for (int i = 0; i < songWords.Count; ++i) { var currentSongWord = songWords[i]; var currentBarWord = currentBarWords[i]; var timeStart = currentSongWord.start; var timeEnd = currentSongWord.end; // Move to currentBarWord while (activeBar != null && activeBar.Id < currentBarWord.barId) { SwitchToNextBar(); } if (currentTime < timeStart) { if (activeBar != null && activeBar.Id == currentBarWord.barId) { activeBar.currentTarget = 0; } break; } else if (currentTime > timeEnd) { barsCompleted = (i == songWords.Count - 1); } else { float tInWord = (currentTime - timeStart) / (timeEnd - timeStart); float t = Mathf.Lerp(currentBarWord.start, currentBarWord.end, tInWord); activeBar.currentTarget = t; songInsideAWord = true; break; } } } if (barsCompleted) { SetActiveBar(null); } } else if (barsCompleted) { songStarted = false; playingSong = false; songSource = null; if (onSongCompleted != null) { onSongCompleted(); } } else { if (songSource != null && !songSource.IsPlaying && !isMenuOpen) { songSource.Stop(); songSource.Play(); songSource.Position = lastSongTime; } } } }