Create a public field on your class of type ‘AnimationCurve’ and use that to get some chance value based on some input:
This way you have a gui in the editor to draw the curve.
You read out the value with the Evaluate method.
What to use as an input is up to you. You can use a ‘experience level’, or the ‘time’ or whatever. That’s up to you on what you want dictating the curve.
The above method is probably the best, but just for knowledge sake…
Another way would be to apply the dice roll logic. Get two random numbers between 1-6.
ok i had time to test it, the problem with first solution is, a cant make animationcurve public. its inside a methode that should be private. so i think i cant use it. for the second one, i have no clue how it works, any code examples?
You can define the AnimationCurve in a public variable outside of the private method, and still use it inside the method. In fact the only time variables can be private or public is when they are member variables, AKA variables that are defined outside of a method.
And if you’re worried about exposing the curve as public, you can set it private and annotate it with [SerializeField]. This will make it appear in the editor but inaccessible from external code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testAnimCurve : MonoBehaviour
{
public AnimationCurve myAnimCurve;
void Update()
{
// Try a preset curve and set the right endpoint to "Loop" or "Ping-Pong"
print(myAnimCurve.Evaluate(Time.time * 0.2f)); // scaled so it's not so fast
}
}