Merge branch 'main' of https://homelab.tailf7f81b.ts.net/tschesky/AppleHillsProduction
This commit is contained in:
69
Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs
Normal file
69
Assets/Scripts/DamianExperiments/Minigame/FlashBehaviour.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class FlashBehaviour : MonoBehaviour
|
||||
{
|
||||
public GameObject square; // Assign in inspector or find in Start
|
||||
public float flashInDuration = 0.05f;
|
||||
public float flashOutDuration = 0.2f;
|
||||
|
||||
private Color squareColor;
|
||||
private Coroutine flashCoroutine;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
if (square == null)
|
||||
square = transform.Find("Square")?.gameObject;
|
||||
|
||||
if (square != null)
|
||||
spriteRenderer = square.GetComponent<SpriteRenderer>();
|
||||
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
squareColor = spriteRenderer.color;
|
||||
squareColor.a = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TriggerFlash()
|
||||
{
|
||||
if (flashCoroutine != null)
|
||||
StopCoroutine(flashCoroutine);
|
||||
flashCoroutine = StartCoroutine(FlashRoutine());
|
||||
}
|
||||
|
||||
private IEnumerator FlashRoutine()
|
||||
{
|
||||
// Fade in
|
||||
float t = 0;
|
||||
while (t < flashInDuration)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
SetAlpha(Mathf.Lerp(0, 1, t / flashInDuration));
|
||||
yield return null;
|
||||
}
|
||||
SetAlpha(1);
|
||||
|
||||
// Fade out
|
||||
t = 0;
|
||||
while (t < flashOutDuration)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
SetAlpha(Mathf.Lerp(1, 0, t / flashOutDuration));
|
||||
yield return null;
|
||||
}
|
||||
SetAlpha(0);
|
||||
}
|
||||
|
||||
private void SetAlpha(float alpha)
|
||||
{
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
squareColor.a = alpha;
|
||||
spriteRenderer.color = squareColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 194155c0137366c4ea64558d2601e19a
|
||||
@@ -29,7 +29,12 @@ namespace Minigames.DivingForPictures
|
||||
[Header("Surfacing Settings")]
|
||||
[Tooltip("Reference to the PlayableDirector that will play the surfacing timeline")]
|
||||
[SerializeField] private PlayableDirector surfacingTimeline;
|
||||
|
||||
|
||||
[Header("Flash Effect Reference")]
|
||||
[Tooltip("Reference to the Flash Effect when the picture is taken")]
|
||||
[SerializeField] private GameObject flashRef;
|
||||
|
||||
|
||||
private CameraViewfinderManager viewfinderManager;
|
||||
|
||||
// Settings reference
|
||||
@@ -871,7 +876,19 @@ namespace Minigames.DivingForPictures
|
||||
|
||||
// Calculate score based on proximity and depth
|
||||
CalculateScore(_currentPhotoTarget, _capturedProximity);
|
||||
|
||||
|
||||
//Trigger the Flash Effect
|
||||
if (flashRef != null)
|
||||
{
|
||||
|
||||
var flash = flashRef.GetComponent<FlashBehaviour>();
|
||||
if (flash != null)
|
||||
{
|
||||
|
||||
flash.TriggerFlash();
|
||||
}
|
||||
}
|
||||
|
||||
// Complete the sequence
|
||||
CompletePhotoSequence();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user