コード例 #1
0
    void Chase()
    {
        rb.position = Vector2.MoveTowards(rb.position, playerTransform.position, chaseSpeed * Time.deltaTime);
        if (enemyType == EnemyType.Slasher)
        {
            if (Random.value < 0.5f)
            {
                if (timeBtwAttack <= 0)
                {
                    StartCoroutine(weapon.Attack(playerTransform.position));
                    timeBtwAttack = startTimeBtwAttack;
                }
                else
                {
                    timeBtwAttack -= Time.deltaTime;
                }
            }
        }

        if (enemyType == EnemyType.Spitter)
        {
            if (Random.value < 0.5f)
            {
                if (timeBtwAttack <= 0)
                {
                    Instantiate(projectile, transform.position, Quaternion.identity);
                    timeBtwAttack = startTimeBtwAttack;
                }
                else
                {
                    timeBtwAttack -= Time.deltaTime;
                }
            }
        }
    }
コード例 #2
0
ファイル: AtkMng.cs プロジェクト: spriggan4/MyProject
 public void Attack()
 {
     //Equip에서 isEquippedWeapon에 값 넣은 후 실행 가능.
     if (isEquippedWeapon)
     {
         enemyWeapon.Attack(this.gameObject.transform);
     }
 }
コード例 #3
0
    private void HandleState()
    {
        if (enemyState == EnemyState.Idle)
        {
            anim.SetBool("Walk", false);
            if (rb.position != patrolPoint)
            {
                rb.position = Vector2.MoveTowards(rb.position, patrolPoint, chaseSpeed * Time.deltaTime);
            }
            else
            {
                float x = Random.Range(transform.position.x - offset, transform.position.x + offset);
                float y = Random.Range(transform.position.y - offset, transform.position.y + offset);
                patrolPoint = new Vector2(x, y);
            }
        }

        if (enemyState == EnemyState.Chase)
        {
            anim.SetBool("Walk", true);
            rb.position = Vector2.MoveTowards(rb.position, playerTransfom.position, chaseSpeed * Time.fixedDeltaTime);
        }

        if (enemyState == EnemyState.Attack)
        {
            changeState = false;
            anim.SetBool("Walk", false);
            if (timeBtwAttack <= 0)
            {
                StartCoroutine(weapon.Attack(playerTransfom.position));
                timeBtwAttack = startTimeBtwAttack;
            }
            else
            {
                timeBtwAttack -= Time.deltaTime;
            }
        }
    }
コード例 #4
0
    private void HandleState()
    {
        if (enemyState == EnemyState.Patroll)
        {
            if (rb.position != patrolPoint)
            {
                rb.position = Vector2.MoveTowards(rb.position, patrolPoint, chaseSpeed * Time.deltaTime);
                anim.SetBool("Walk", true);
            }
            else
            {
                patrolPoint = SetRandomPosition(patrolPoint, offset);
            }
        }

        if (enemyState == EnemyState.Chase)
        {
            if (enemyType == EnemyType.Puncher)
            {
                anim.SetBool("Walk", true);
                rb.position = Vector2.MoveTowards(rb.position, playerTransform.position, chaseSpeed * Time.deltaTime);
            }
            if (enemyType == EnemyType.Slasher)
            {
                anim.SetBool("Walk", true);
                rb.position = Vector2.MoveTowards(rb.position, playerTransform.position, chaseSpeed * Time.deltaTime);
                if (timer <= 0)
                {
                    if (Random.value < .5f)
                    {
                        StartCoroutine(weapon.Attack(playerTransform.position));
                    }
                    timer = 1f;
                }
                else
                {
                    timer -= Time.deltaTime;
                }
            }
        }

        if (enemyState == EnemyState.Attack)
        {
            rb.position = transform.position;
            if (enemyType == EnemyType.Puncher)
            {
                anim.SetBool("Walk", false);
                if (timeBtwAttack <= 0)
                {
                    StartCoroutine(Attack());
                    timeBtwAttack = startTimeBtwAttack;
                }
                else
                {
                    timeBtwAttack -= Time.deltaTime;
                }
            }

            if (enemyType == EnemyType.Slasher)
            {
                anim.SetBool("Walk", false);
                if (timeBtwAttack <= 0)
                {
                    StartCoroutine(weapon.Attack(playerTransform.position));
                    timeBtwAttack = startTimeBtwAttack;
                }
                else
                {
                    timeBtwAttack -= Time.deltaTime;
                }
            }
        }
    }
コード例 #5
0
 private void Explode()
 {
     explosion.Attack();
 }