利用Animation Curve(lookup curve)來設定亂數分布的方法

http://unitytips.tumblr.com/post/67259382850/use-animationcurve-to-define-probabilistic-random

蠻有趣的使用,利用Animation Curve(lookup curve)來設定亂數分布的方法

using UnityEngine;
using System.Collections;

public class ProbabilisticDamage : MonoBehaviour {
    public AnimationCurve distribution;
    public float maxDamage;
    public float minDamage;

    public float randomDamage {
        get {
            // Get a random number between 0 and 1
            float x = Random.value;

            // Find that value on your distribution curve
            float y = distribution.Evaluate(x);

            // Scale it to be between your max and min
            return minDamage + (y * (maxDamage - minDamage));
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *