Example #1
0
    void FixedUpdate()
    {
        attackDelay -= Time.fixedDeltaTime;

        if (target == null)
        {
            foreach (PlayerMain player in battleGameScene.players)
            {
                if (player.team != playerMain.team)
                {
                    target = player;
                    break;
                }
            }
        }
        else
        {
            float distance = Vector3.Distance(target.transform.position, transform.position);
            if (distance >= defAttackDistance)
            {
                playerMain.LookAt(target.transform.position);
                playerMain.Advance();
            }
            else
            {
                playerMain.Stop();

                if (attackDelay <= 0)
                {
                    playerMain.Attack(target.transform.position);
                    attackDelay = defAttackDelay;
                }
            }
        }
    }