Skip to content

Instantly share code, notes, and snippets.

@phosphoer
Created December 4, 2018 19:43
Show Gist options
  • Save phosphoer/fc798070bc6f9217b3e38decefa8c25e to your computer and use it in GitHub Desktop.
Save phosphoer/fc798070bc6f9217b3e38decefa8c25e to your computer and use it in GitHub Desktop.
CurveExample.cs
using UnityEngine;
using MinMaxCurve = UnityEngine.ParticleSystem.MinMaxCurve;
public class CurveExample : MonoBehaviour
{
[Range(0, 10)]
public int CurrentLevel = 0;
public int LevelCount = 10;
public float CalculatedProgression;
public float CalculatedDifficulty;
public int CalculatedEnemyMin;
public int CalculatedEnemyMax;
// Author a difficulty curve where x is the % of the way through the game
[SerializeField]
private AnimationCurve difficultyCurve = null;
// Author as many curves like this as you want, where x is the current difficulty
[SerializeField]
private MinMaxCurve enemyCountCurve = default(MinMaxCurve);
private void Update()
{
// Get the normalized progression value
CalculatedProgression = CurrentLevel / (float)LevelCount;
// Evaluate the difficulty value for this progression value
CalculatedDifficulty = difficultyCurve.Evaluate(CalculatedProgression);
// Evaluate the minmax curve for this difficulty, the second parameter to Evaluate is the
// % between the min and max curve
CalculatedEnemyMax = Mathf.RoundToInt(enemyCountCurve.Evaluate(CalculatedDifficulty, 1));
CalculatedEnemyMin = Mathf.RoundToInt(enemyCountCurve.Evaluate(CalculatedDifficulty, 0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment