private void TargetAttack(float speed, float range)
    {
        switch (controlType)
        {
        case ControlType.AI:

            break;

        case ControlType.PLAYER:
            EnemySpawn nextClosestEnemy = EnemySpawn.GetClosestEnemy(transform.position, range);
            if (nextClosestEnemy != null && Vector2.Distance(transform.position, nextClosestEnemy.transform.position) > 2f)
            {
                Vector2 nextTargetDir = (nextClosestEnemy.transform.position - transform.position).normalized;
                velocity = (nextTargetDir * speed);
                //transform.position = Vector2.MoveTowards(transform.position, nextClosestEnemy.transform.position, speed);
                //Debug.Log("enemy at " + nextClosestEnemy.transform.position);
            }
            else
            {
                //Debug.Log("no one nearby");
            }
            break;

        default:
            break;
        }
    }
예제 #2
0
    public void AttackClosestEnemy()
    {
        hitbox.RestoreGetHitBools();
        EnemySpawn nextClosestEnemy = EnemySpawn.GetClosestEnemy(transform.position, targetNextEnemyDistance);

        if (nextClosestEnemy != null)
        {
            nextTargetDir = (nextClosestEnemy.transform.position - transform.position).normalized;
            TargetNextEnemy();
        }
    }
    private void Update()
    {
        switch (bulletType)
        {
        case 0:    //fly straight
            break;

        case 1:    //home in
            transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed);
            break;

        case 2:    //fly firectly at target
            transform.Translate(moveDirection * Time.deltaTime);
            break;

        case 3:    //home in on closest enemy
            closestEnemy = EnemySpawn.GetClosestEnemy(transform.position, targetRange);
            if (closestEnemy != null)
            {
                transform.position = Vector2.MoveTowards(transform.position, closestEnemy.transform.position, speed);
            }
            break;

        case 4:     //follow ground
            Vector2 velocity = new Vector2(transform.localScale.x * speed, -2);
            velocity.y += gravity;
            controller.Move(velocity * Time.deltaTime, direction);
            break;
        }
        //Countdown to lifetime
        if (lifeTime > 0)
        {
            lifeTime -= Time.deltaTime;
        }
        else if (lifeTime <= 0)
        {
            Destroy(gameObject);
        }
    }
예제 #4
0
    private void FixedUpdate()
    {
        switch (bulletType)
        {
        case 0:    //fly straight
            transform.Translate(velocity * speed * Time.fixedDeltaTime);
            break;

        case 1:    //home in
            transform.position = Vector2.MoveTowards(transform.position, target.transform.position, (speed / 80));
            break;

        case 2:    //fly firectly at target
            transform.Translate(velocity * Time.fixedDeltaTime);
            break;

        case 3:    //home in on closest enemy
            closestEnemy = EnemySpawn.GetClosestEnemy(transform.position, targetRange);
            if (closestEnemy != null)
            {
                transform.position = closestEnemy.transform.position;
            }
            break;

        case 4:     //follow ground

            thisBullet.FrontVelocity(speed * transform.localScale.x);
            break;
        }
        //Countdown to lifetime
        if (lifeTime > 0)
        {
            lifeTime -= Time.fixedDeltaTime;
        }
        else if (lifeTime <= 0)
        {
            OnDestroyGO();
        }
    }