Ejemplo n.º 1
0
    void ShootPlayer()
    {
        if (player == null)
        {
            return;
        }
        Debug.Log("EnemyAI is shooting");
        GameObject  bulletObj = Instantiate(bulletPrefab, gameObject.transform.position + new Vector3(0, 0, 0.01f), Quaternion.identity);
        BulletEnemy bullet    = (BulletEnemy)bulletObj.GetComponent <BulletEnemy>();

        bullet.setDirection(player.transform.position - gameObject.transform.position);
        bullet.setSpeed(Globals.ENEMY_SHOOTER_BULLET_SPEED);
    }
Ejemplo n.º 2
0
    private void Shoot()
    {
        GameObject  player    = GameFlow.Instance.player;
        GameObject  bulletObj = Instantiate(bulletPrefab, gameObject.transform.position + new Vector3(0, 0, 0.01f), Quaternion.identity);
        BulletEnemy bullet    = (BulletEnemy)bulletObj.GetComponent <BulletEnemy>();

        Vector2 dirVec    = player.transform.position - gameObject.transform.position;
        Vector2 normVec   = new Vector2(dirVec.y, -dirVec.x);
        Vector2 randomVec = normVec * Random.Range(-0.3f, 0.3f);
        Vector2 totalVec  = dirVec + randomVec;

        bullet.setDirection(totalVec);

        bullet.setSpeed(Globals.ENEMY_SHOOTER_BULLET_SPEED);
    }