private void Shoot()
    {
        Transform shootPoint = gameObject.transform.FindChild("ShootPoint");

        if (elapsedTime >= shootRate)
        {
            (Instantiate(attackParticle, shootPoint.position, transform.rotation) as GameObject)
            .transform.parent = gameObject.transform;
            EnemyAni.PlayAttack();
            sound.PlaySound(gameObject.transform);
            elapsedTime = 0.0f;
        }
    }
Beispiel #2
0
    private void Update()
    {
        float distance = Vector3.Distance(target.position, transform.position);

        if (distance <= agent.stoppingDistance)
        {
            attackTimer += Time.deltaTime;
        }
        else
        {
            attackTimer = 0;
        }

        if (distance <= agent.stoppingDistance && attackTimer > attackTimeFrequency && !isDead)
        {
            DoDamageToPlayer();
            enemyAnimation.PlayAttack();
            attackTimer = 0f;
        }

        enemyAnimation.SetRunSpeed(!(agent.velocity.x == 0 && agent.velocity.y == 0 && agent.velocity.z == 0) ? 1f : 0f);
        hitTimer   += Time.deltaTime;
        rb.position = transform.position;
    }