我为熊创造了一个非常简单的AI。我想让它在攻击范围内攻击()玩家。当它发生时,它会从0到1取一个数字,并且根据该数字,熊正在播放一个选定的动画。 之后它将根据它等施加伤害等。
问题是功能Attack()似乎不起作用。啤酒一直在我身边走。
var distance : float;
var fps : GameObject;
var target : Transform;
var sight : float = 20.0;
var aggroRange : float = 35;
var moveSpeed : float = 4.0;
var health : int = 120;
var attackRange : float = 2.0;
var damage : float = 0.1;
var cooldown : float = 3.0;
var roll : float;
var damping : float = 6.0;
var gravity : float = 100.0;
private var moveDirection : Vector3 = Vector3.zero;
var controller : CharacterController;
function Start()
{
playerm = GameObject.Find("Player_Model");
target = playerm.transform;
}
function Update()
{
if(health <= 0)
{
Destroy(this.gameObject);
}
distance = Vector3.Distance(target.position, transform.position);
if(distance > aggroRange)
{
Stop();
}
if(distance < sight)
{
LookAt();
Chase();
animation.Play("Walk");
}
if(distance <= attackRange)
{
if(cooldown <= 0)
{
Attack();
}
}
}
function LookAt()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function Chase()
{
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function Stop()
{
animation.Play("Idle");
animation["Idle"].speed = 0.5;
}
function Attack()
{
roll = Random.Range(0, 0.1);
if(roll == 0)
{
animation.Play("Maul");
}
else
{
animation.Play("Bite");
}
cooldown = 3.0;
}
我无法真正发现错误 - Unity没有显示任何错误,而且在编码时我是一个乞丐。
非常感谢帮助。