//注意,这个脚本要和unity自带的smoothlookat、ConstantForce一起放置到“敌人”上,“敌人”需要添加rigidbody
var detectObject: Transform;
var distanceDetection: float;
function Update () {
if (detectObject) {
var dist = Vector3.Distance(detectObject.position, transform.position);
//if distance is less than what is specified then do something
if(dist<distanceDetection){
//print("attack");
GetComponent(SmoothLookAt).enabled = true;
GetComponent(ConstantForce).enabled = true;
}else{
//print("stop attack");
GetComponent(SmoothLookAt).enabled = false;
GetComponent(ConstantForce).enabled = false;
}
}
}