Commit e58e68d9 authored by saad's avatar saad

increase tick sound speed over time

bug: the tick sound doesn't work in mcq game
parent 70812d7e
......@@ -707,7 +707,7 @@ MonoBehaviour:
classCode:
runSpeed: 8
lives: 5
startTime: 60
startTime: 100
correctAnswerBonusTime: 10
wrongAnswerPenaltyTime: 10
useOfflineTestData: 0
......
......@@ -7,6 +7,7 @@ using UnityEngine.Events;
namespace com.al_arcade.cs
{
using com.al_arcade.mcq;
using shared;
using Unity.Cinemachine;
......@@ -56,7 +57,7 @@ namespace com.al_arcade.cs
private int _deltaChangeInSize;
private bool _showHint = true;
private Camera _cam;
private float _quarterTime;
CinemachineTargetGroup _targetGroup;
CinemachineGroupFraming _groupFraming;
......@@ -122,17 +123,24 @@ namespace com.al_arcade.cs
protected override void OnTimerTick(float timeLeft)
{
// Ticking sound when under 4 seconds
if (timeLeft < 4f && !_isTicking)
float quarter = CsPrefabBuilder.Instance.startTime / 4f;
if (timeLeft < quarter && !_isTicking)
{
_isTicking = true;
SSAudioManager.Instance?.Tick(true);
}
else if (timeLeft >= 4f && _isTicking)
else if (timeLeft >= quarter && _isTicking)
{
_isTicking = false;
SSAudioManager.Instance?.Tick(false);
}
if (_isTicking)
{
float t = 1f - (timeLeft / quarter);
float pitch = Mathf.Lerp(1f, 2.5f, t);
SSAudioManager.Instance?.SetTickPitch(pitch);
}
uiManager?.SetTimer(timeLeft);
}
......@@ -176,6 +184,7 @@ namespace com.al_arcade.cs
onGameStart?.Invoke();
StartCoroutine(QuestionLoop());
_quarterTime = CsPrefabBuilder.Instance.startTime / 4;
}
// ─── Update: CS also needs the state guard from original ─────────────
......@@ -240,13 +249,12 @@ namespace com.al_arcade.cs
// ─── Timer helpers ────────────────────────────────────────────────────
private void AdjustTimer(float delta)
{
UpdateTimerBy(delta);
_timeLeft = Mathf.Clamp(_timeLeft, 0, CsPrefabBuilder.Instance.startTime);
_timeLeft = Mathf.Clamp(_timeLeft + delta, 0f, CsPrefabBuilder.Instance.startTime);
// Re-check tick state after adjustment
if (_timeLeft < 4f && !_isTicking)
if (_timeLeft < _quarterTime && !_isTicking)
{ _isTicking = true; SSAudioManager.Instance?.Tick(true); }
else if (_timeLeft >= 4f && _isTicking)
else if (_timeLeft >= _quarterTime && _isTicking)
{ _isTicking = false; SSAudioManager.Instance?.Tick(false); }
uiManager?.UpdateTimer(_timeLeft, delta > 0);
......
......@@ -505,9 +505,9 @@ namespace com.al_arcade.cs
public void SetTimer(float time)
{
if (isTweening) return;
_timerSlider.value = time / 30f;
_timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger;
float quarter = CsPrefabBuilder.Instance.startTime / 4f;
_timerSlider.value = time / CsPrefabBuilder.Instance.startTime;
_timerFill.color = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
}
public void EnableScore(bool value)
{
......@@ -525,27 +525,22 @@ namespace com.al_arcade.cs
public void UpdateTimer(float time, bool pos)
{
isTweening = true;
float quarter = CsPrefabBuilder.Instance.startTime / 4f;
var color = pos ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
_timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f);
_timerFill.DOColor(color, 0.2f).SetEase(Ease.OutQuad).OnComplete(() =>
{
_timerFill.DOColor(_timerDefaultColor, 0.2f).SetEase(Ease.OutQuad);
});
var targetTime = time;
// ✅ after the flash, return to red if still in danger zone, normal if above quarter
Color restingColor = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
// Account for tween time
if (!pos)
{
targetTime -= 0.3f;
}
_timerSlider.DOValue(targetTime / 30f, 0.3f).SetEase(Ease.OutQuad).OnComplete(() =>
var flashColor = pos ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
_timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f);
_timerFill.DOColor(flashColor, 0.2f).SetEase(Ease.OutQuad).OnComplete(() =>
{
isTweening = false;
_timerFill.DOColor(restingColor, 0.2f).SetEase(Ease.OutQuad); // ✅ smart resting color
});
var targetTime = pos ? time : time - 0.3f;
_timerSlider.DOValue(targetTime / CsPrefabBuilder.Instance.startTime, 0.3f)
.SetEase(Ease.OutQuad)
.OnComplete(() => isTweening = false);
}
public void ResetUI()
......
......@@ -190,13 +190,11 @@ namespace com.al_arcade.mcq
public void SetTimer(float time)
{
if (_isTweening) return;
float quarter = McqPrefabBuilder.Instance.startTime / 4f;
if (_timerSlider != null)
_timerSlider.value = time / McqPrefabBuilder.Instance.startTime;
if (_timerFill != null)
_timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger;
_timerFill.color = time > quarter ? _timerDefaultColor : SSColorPalette.Danger; // ✅ red below quarter
if (_timerText != null)
_timerText.Text = Mathf.CeilToInt(time).ToString();
}
......@@ -205,21 +203,22 @@ namespace com.al_arcade.mcq
public void UpdateTimer(float time, bool positive)
{
_isTweening = true;
float quarter = McqPrefabBuilder.Instance.startTime / 4f;
var flashColor = positive ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
// ✅ after flash, go red if still in danger zone, normal if bonus pushed us above quarter
Color restingColor = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
var flashColor = positive ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
if (_timerSlider != null)
_timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f);
if (_timerFill != null)
{
_timerFill.DOColor(flashColor, 0.2f).SetEase(Ease.OutQuad)
.OnComplete(() =>
_timerFill.DOColor(_timerDefaultColor, 0.2f).SetEase(Ease.OutQuad));
_timerFill.DOColor(restingColor, 0.2f).SetEase(Ease.OutQuad)); // ✅ smart resting color
}
float targetTime = positive ? time : time - 0.3f;
if (_timerSlider != null)
{
_timerSlider.DOValue(targetTime / McqPrefabBuilder.Instance.startTime, 0.3f)
......

using UnityEngine;
using System.Collections.Generic;
......@@ -87,18 +87,26 @@ namespace com.al_arcade.shared
{
if (start)
{
if (_tickingSource.isPlaying)
{
_tickingSource.Stop();
}
if (_tickingSource.isPlaying) return; // ✅ prevent restart
_tickingSource.clip = tickingLoop;
_tickingSource.loop = true; // ✅ IMPORTANT
_tickingSource.pitch = 1f; // reset
_tickingSource.Play();
}
else
{
if (_tickingSource.isPlaying)
_tickingSource.Stop();
}
}
// ADD this new method below the existing Tick() method
public void SetTickPitch(float pitch)
{
if (_tickingSource != null && _tickingSource.isPlaying)
_tickingSource.pitch = Mathf.Clamp(pitch, 1f, 3f);
}
public void StopMusic()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment