Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (Vector3.Distance(transform.position, target) <= 2)
     {
         movementController.stop();
     }
 }
Esempio n. 2
0
    void Update()
    {
        float      distance = Vector3.Distance(transform.position, target.transform.position);
        Ray        ray      = new Ray(transform.position, (target.transform.position - transform.position).normalized);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, distance + 10))
        {
            if (Vector3.Distance(hit.point, transform.position) <= attackComponent.getAttackRange() && (hit.collider.gameObject.layer == 10 || hit.collider.gameObject.layer == 15))
            {
                movementController.stop();
                attackComponent.AttackTo(target);
            }
            else
            {
                movementController.moveTo(target.transform.position);
            }
        }
        else
        {
            movementController.moveTo(target.transform.position);
        }
    }