Created
February 14, 2024 07:59
-
-
Save FUJI-bayashi/e1d943cb2a430ad899c03ab1b545c465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class GunFireRateControl : MonoBehaviour | |
{ | |
// Threshold for the number of shots to trigger the Dizzy effect | |
public int shotsThreshold = 5; | |
// Time window in seconds to count the shots | |
public float countingWindow = 2f; | |
// Counter for shots fired in the time window | |
private int shotsCounter = 0; | |
// Timer to track the counting window | |
private float timer = 0; | |
// Flag to check if Dizzy effect is currently active | |
private bool isDizzyActive = false; | |
void Update() | |
{ | |
// Check if the countdown is active | |
if (timer > 0) | |
{ | |
// Decrease the timer | |
timer -= Time.deltaTime; | |
} | |
else if (shotsCounter > 0) | |
{ | |
// Reset the counter when the time window has passed without reaching the threshold | |
ResetShotsCounter(); | |
} | |
// Example condition to check for gun firing, replace with your own condition | |
if (Input.GetButtonDown("Fire1")) | |
{ | |
ProcessShotFired(); | |
} | |
} | |
void ProcessShotFired() | |
{ | |
if (timer <= 0) | |
{ | |
// Start the countdown | |
timer = countingWindow; | |
} | |
// Increment the shots counter | |
shotsCounter++; | |
// Check if the shots threshold is exceeded | |
if (shotsCounter >= shotsThreshold) | |
{ | |
TriggerDizzyEffect(); | |
ResetShotsCounter(); | |
} | |
} | |
void TriggerDizzyEffect() | |
{ | |
// Apply the Dizzy effect here | |
if (!isDizzyActive) | |
{ | |
isDizzyActive = true; | |
Debug.Log("Dizzy effect triggered!"); | |
// Extend Dizzy effect if already active or apply it for the first time | |
} | |
// Reset or extend the Dizzy effect duration as needed | |
} | |
void ResetShotsCounter() | |
{ | |
// Reset the counter and timer | |
shotsCounter = 0; | |
timer = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment