属性:
Mathf.Deg2Rad 表示从角度到弧度转变的常量值,其值为(2*Mathf.PI)/360
Mathf.Rad2Deg 表示从弧度到角度转变的常量值,其值为360/(2*Mathf.PI)
方法:
public static int Clamp(int value, int min, int max);
此方法用来返回有范围限制的value值,当value在范围[min,max]内时返回value值;当value
public class SmoothStep : MonoBehaviour {
public float minimum = 0.0F;
public float maximum = 10.0F;
void Update()
{
float smoothStepvalue = Mathf.SmoothStep(minimum, maximum, Time.time);
transform.position = new Vector3(smoothStepvalue, 1, 0);
}
}
public class Lerp : MonoBehaviour {
// Use this for initialization
public float minimum = 0.0F;
public float maximum = 10.0F;
// Update is called once per frame
void Update () {
float lerpValue = Mathf.Lerp(minimum, maximum, Time.time);
transform.position = new Vector3(lerpValue, -2, 0);
}
}
public class SmoothDamp : MonoBehaviour
{
public Transform target;
public float smoothTime = 1F;
private float yVelocity = 0.0F;
void Update()
{
float newPosition = Mathf.SmoothDamp(transform.position.x, target.position.x, ref yVelocity, smoothTime);
transform.position = new Vector3(newPosition, transform.position.y, transform.position.z);
}
}
public class SmoothDampAngle : MonoBehaviour {
public Transform target;
public float smooth = 0.3F;
public float distance = 5.0F;
private float yVelocity = 0.0F;
void Update()
{
float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, 180, ref yVelocity, smooth);
transform.rotation = Quaternion.Euler(0, yAngle, 0);
}
}
public class LerpAngle : MonoBehaviour {
// Use this for initialization
void Start () {
float a,b,f;
a = -50.0f;
b = 400.0f;
f = Mathf.LerpAngle(a, b, 0.3f);
//a规范化后的值为360-50=310,b规范化后的值为-360+400=40
//a沿逆时针方向经90度后到达b,所以插值返回值f=a+c*t=-50+90*0.3
a = 400f;
b = -50f;
f = Mathf.LerpAngle(a, b, 0.3f);
//a规范化后的值为-360+400=40,b规范化后的值为360-50=310
//a沿顺时针方向经90度后到达b,所以插值返回值f=a-c*t=400-90*0.3
}
}