Example #1
0
    public override void OnStart()
    {
        enermyHealth = this.GetComponent <EnermyHealth>();
        HP           = enermyHealth.HP;
        fleeHP       = enermyHealth.fleeHP;
        animator.SetBool("isInView", false);
        // initially move towards the closest waypoint
        float distance = Mathf.Infinity;
        float localDistance;

        for (int i = 0; i < waypoints.Value.Count; ++i)
        {
            if ((localDistance = Vector3.Magnitude(transform.position - waypoints.Value[i].position)) < distance)
            {
                distance      = localDistance;
                waypointIndex = i;
            }
        }

        // set the speed, angular speed, and destination then enable the agent
        navMeshAgent.speed        = speed.Value;
        navMeshAgent.angularSpeed = angularSpeed.Value;
        navMeshAgent.enabled      = true;
        navMeshAgent.destination  = Target();
    }
Example #2
0
 public override void OnStart()
 {
     Debug.Log("startChasing!!!");
     //target=GameObject.Find()
     animator = this.GetComponent <Animator>();
     animator.SetBool("isInView", true);
     enermyHealth = this.GetComponent <EnermyHealth>();
     HP           = enermyHealth.HP;
     fleeHP       = enermyHealth.fleeHP;
     Debug.Log("Hp is " + HP);
     sqrViewDistance = viewDistance.Value * viewDistance.Value;
     //启用导航组件
     navMeshAgent.enabled      = true;
     navMeshAgent.speed        = speed.Value;
     navMeshAgent.angularSpeed = angularSpeed.Value;
     navMeshAgent.destination  = target.Value.position;
 }
    void OnTriggerEnter(Collider other)
    {
        EnermyHealth enermyHealth = other.gameObject.GetComponent <EnermyHealth>();
        PlayerHealth playerHealth = other.gameObject.GetComponent <PlayerHealth>();

        if (other.gameObject.tag.Equals("Enermy") && !isExplode)
        {
            if (enermyHealth != null)
            {
                enermyHealth.TakeDamge(20);
            }
            Explode();
            isExplode = true;
        }
        if (other.gameObject.tag.Equals("Player") && !isExplode)
        {
            if (playerHealth != null)
            {
                playerHealth.TakeDamge(20);
            }
            Explode();
            isExplode = true;
        }
    }