Mathf.Clamp01
Deklarasyon
public static float Clamp01(float value);
Açıklama
Değeri 0 ile 1 arasında sınırlar ve değeri döndürür.
Eğer değer negatifse, sıfır döndürülür. Değer birden büyükse, bir döndürülür.
using UnityEngine;
public class Example : MonoBehaviour
{
// Transform'un konumunu zamanın konumuna ayarlayın
// ancak asla 0'dan küçük veya 1'den büyük olmasın
void Update()
{
transform.position = new Vector3(Mathf.Clamp01(Time.time), 0, 0);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Her saniye rastgele bir sayı yazdırır. Bu sayı, startValue ile endValue arasında seçilir.
// Rastgele sayı, Clamp01() ile sıfır ile bir arasında sınırlandırılır.
public class ExampleScript : MonoBehaviour
{
public float startValue = -0.5f;
public float endValue = 1.5f;
private float timeCount = 0.0f;
void FixedUpdate()
{
timeCount += Time.deltaTime;
if (timeCount > 1.0f)
{
float result = Random.value;
result = result * (endValue - startValue);
result = result + startValue;
float clampValue = Mathf.Clamp01(result);
Debug.Log("value: " + result.ToString("F3") + " result: " + clampValue.ToString("F3"));
timeCount = 0.0f;
}
}
}
Bu blog Unity Docs'un Türkçeye çevrilmiş halidir.
Yorumlar
Yorum Gönder