-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections; | ||
using UnityEngine; | ||
|
||
public class BeatBonker : MonoBehaviour | ||
{ | ||
[Header("Beat Configuration")] | ||
public float bpm = 130f; // beats per minute | ||
public float initialDelay = 0.5f; // delay before the first beat | ||
|
||
[Header("Size Increase Configuration")] | ||
public float scaleFactor = 1.3f; // how much to scale the ship on the beat | ||
public float duration = 0.2f; // duration of the scale effect | ||
|
||
public float chanceToTrigger = 1; | ||
|
||
private Vector3 initialScale; | ||
|
||
private void Start() | ||
{ | ||
initialScale = transform.localScale; | ||
|
||
InvokeRepeating("TriggerBeat", initialDelay, 60f / bpm); | ||
} | ||
|
||
void TriggerBeat() | ||
{ | ||
if (Random.Range(0.0f, 1.0f) <= chanceToTrigger) | ||
{ | ||
StartCoroutine(ScaleOnBeat()); | ||
} | ||
} | ||
|
||
IEnumerator ScaleOnBeat() | ||
{ | ||
float elapsed = 0f; | ||
|
||
while (elapsed < duration) | ||
{ | ||
float currentScaleFactor = Mathf.Sin((elapsed / duration) * Mathf.PI) * (scaleFactor - 1) + 1; | ||
transform.localScale = initialScale * currentScaleFactor; | ||
|
||
elapsed += Time.deltaTime; | ||
yield return null; | ||
} | ||
|
||
transform.localScale = initialScale; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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