计算角色和物体之间距离来触发动画【Unity3d】
function Update () { var aa = GameObject.Find("tishen"); var bb =GameObject.Find("xar"); var dis : float=Vector3.Distance(aa.transform.position, bb.transform.position); if (dis>5.0 && dis<=7.0 ) { animation.Play("xarzx"); } else if (dis>7.0) { animation.Play("idle"); } else animation.Play("xarjh"); }