Exemple #1
0
    void Update()
    {
        if (target == null)
        {
            target = ProceduralMap.pla;
        }

        dist = target.transform.position - transform.position;
        if (dist.magnitude < 10)
        {
            anim.SetBool("VerifyPos", false);
            anim.SetBool("View", true);
            agent.SetDestination(target.transform.position);
            if (dist.magnitude < 2f)
            {
                agent.SetDestination(transform.position);
                timerForAttack -= Time.deltaTime;
                if (timerForAttack <= 0)
                {
                    anim.SetTrigger("Attack");
                    int randomDamage = Random.Range(15, 30);
                    pf.AddDamage(randomDamage);
                    timerForAttack = nextAttack;
                }
            }
        }
        else
        {
            anim.SetBool("View", false);
            agent.SetDestination(startPos);
            distToOwner = startPos - transform.position;
            if (distToOwner.magnitude <= 1)
            {
                anim.SetBool("VerifyPos", true);
            }
        }
    }