private void Update() { enemy = enemyFinder.FindEnemy(gameObject, RADIUS); if (enemy == null) { return; } count -= Time.deltaTime; if (count < 0) { count = ATTACK_RATE; GameObject bullet = DGameSystem.LoadPool("Bullet", attacker.transform.position); bullet.GetComponent <Rigidbody2D>().velocity = DGameSystem.GoToTargetVector(attacker.transform.position, enemy.transform.position, BULLET_SPEED); } }
private void Update() { if (owner == null) { enemyTag = "Player"; } else { enemyTag = "Monster"; } if (enemy != null) { if (Vector3.Distance(transform.position, enemy.transform.position) < visionRange) { state = STATE.ATTACK; } else { enemy = FindEnemy(enemyTag); if (enemy != null) { state = STATE.ATTACK; } else { state = STATE.FREE; } } } else { enemy = FindEnemy(enemyTag); if (enemy != null) { state = STATE.ATTACK; } else { state = STATE.FREE; } } if (state == STATE.ATTACK) { GetComponent <DMovementExecutor>().enabled = false; GetComponent <DMovement>().enabled = false; if (Vector3.Distance(transform.position, enemy.transform.position) < stat.attackRange) { GetComponent <DAnimator>().spritesheet = getSprite("attack", enemy); GetComponent <Rigidbody2D>().velocity = Vector3.zero; attackCount -= Time.deltaTime; if (attackCount < 0) { attackCount = stat.attackCountDown; GetComponent <DBattle>().ApplyDame(enemy); } } else { GetComponent <DAnimator>().spritesheet = getSprite("run", enemy); GetComponent <Rigidbody2D>().velocity = DGameSystem.GoToTargetVector(transform.position, enemy.transform.position, stat.speed * 1.5f); } } else // STATE == FREE { if (owner != null) { GetComponent <DAnimator>().spritesheet = getSprite("go", owner); GetComponent <Rigidbody2D>().velocity = DGameSystem.GoToTargetVector(transform.position, enemy.transform.position, stat.speed); } else { GetComponent <DMovementExecutor>().enabled = true; GetComponent <DMovement>().enabled = true; } } }