【发布时间】:2016-08-28 09:51:29
【问题描述】:
这也是一个视频 - http://tinypic.com/r/mmagki/9
这是我的 start() 函数
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
和 update() 函数
void Update()
{
transform.LookAt(target);
float step = speed * Time.deltaTime;
distance = (transform.position - target.position).magnitude;
//Debug.Log("Now distance -" + distance);
if (distance < 20)
{
// print("In Range");
transform.GetComponent<Animation>().Play("attack", PlayMode.StopAll);
if (isAttacking == false)
{
isAttacking = true;
Hit.playerHealth -= Random.Range(20f, 25f) * Time.deltaTime;
Hit.playerHealth -= Random.Range(20f, 25f);
// StartCoroutine(MyCoroutine(4));
// print("Player Health Status = " + Hit.playerHealth);
if (Hit.playerHealth <= 0)
{
// print("Player dead");
}
}
else
{
}
}
else
{
// print("Out of Range");
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
transform.GetComponent<Animation>().Play("walk", PlayMode.StopAll);
}
}
我的僵尸(敌人)正在接近玩家,当僵尸被墙击中时,他应该去大门。
我做了什么,当 Zombie (Set Trigger = checked) 撞墙时,我将“目标”的引用更改为 Object with tag 'gate'。
现在僵尸没有向门对象移动(我也设置了标签“门”)。他仍然只向玩家移动。无法更改目标的参考。
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "wall")
{
target = GameObject.FindGameObjectWithTag("gate").transform;
Debug.Log("Yes its a onTrigger Enter function , hitting with wall");
}
}
【问题讨论】: