Attack() приватный Метод

private Attack ( ) : void
Результат void
Пример #1
0
    private IEnumerator PlayTurnRoutine()
    {
        if (m_GameManager != null && !m_GameManager.IsGameOver)
        {
            m_enemySensor.SenseNode(m_enemyMover.CurrentNode);

            yield return(new WaitForSeconds(0.0f));

            if (m_enemySensor.FindPlayer)
            {
                m_GameManager.LoseLevel();
                Vector3 playPos = new Vector3(m_board.PlayerNode.Coordinate.x, 0f, m_board.PlayerNode.Coordinate.y);
                m_enemyMover.Move(playPos, 0f);

                while (m_enemyMover.isMoving)
                {
                    yield return(null);
                }
                //attach player
                m_enemyAttack.Attack();
            }
            else
            {
                //move
                m_enemyMover.MoveOneTurn();
            }
        }
    }
Пример #2
0
 // Update is called once per frame
 void Update()
 {
     if (health.isDead)
     {
         agent.ResetPath();
     }
     else
     {
         bool inAttackRange = Vector3.Distance(transform.position, player.transform.position) <= stoppingDistance;
         anim.SetBool("Walking", !inAttackRange);
         if (player)
         {
             if (inAttackRange)
             {
                 agent.ResetPath();
                 attack.Attack();
             }
             else
             {
                 agent.SetDestination(player.transform.position);
             }
             //Charge();
             //Debug.Log(Vector3.Distance(transform.position, player.transform.position));
         }
     }
 }
Пример #3
0
    IEnumerator PlayTurnRoutine()
    {
        if (_gameManager != null && !_gameManager.IsGameOver)
        {
            _enemySensor.UpdateSensor(_enemyMove.CurrentNode);
            yield return(new WaitForSeconds(.5f));

            if (_enemySensor.FoundPlayer)
            {
                _gameManager.LoseLevel();

                Vector3 playerPosition = new Vector3(_gameBoard.PlayerNode.Coordinate.x, 0f,
                                                     _gameBoard.PlayerNode.Coordinate.y);
                _enemyMove.Move(playerPosition, 0f);
                while (_enemyMove.isMoving)
                {
                    yield return(null);
                }
                _enemyAttack.Attack();
            }
            //attack player

            //movement
            else
            {
                _enemyMove.MoveOneTurn();
            }
        }
        //wait
    }
Пример #4
0
    private void Attack()
    {
        // Cant attack yet, we kite
        if (!attackScript.canAttack)
        {
            // If doesn't kite we continue running towards player
            if (attackScript.kites)
            {
                RunAway();
                return;
            }
        }

        // If distance from this to player is more than attack distance we run closer until we can attack
        if ((PlayerController.Instance.transform.position - transform.position).sqrMagnitude > attackScript.attackDistance * attackScript.attackDistance)
        {
            RunToPlayer();
        }
        else if (attackScript.isRanged && CollisionCheck(attackScript.attackDistance))
        {
            AvoidObstacleRanged();
        }
        else
        {
            attackScript.Attack();
        }
    }
Пример #5
0
    /// <summary>
    /// This function will check if the object is inrange of the target, if so attack the target, if not walk towards the target.
    /// </summary>
    private void InRange()
    {
        float distance = (_target.transform.position - transform.position).magnitude;

        if (distance < _range)
        {
            if (_cooldown == 0)
            {
                _attack.Attack();
                _cooldown = 5f;
            }
        }
        else
        {
            Vector2 direction = GetMovementDirection();
            Vector2 tPos      = transform.position;
            tPos.x            += direction.x * _speed * Time.deltaTime;
            transform.position = tPos;
        }
        if (_cooldown > 0f)
        {
            _cooldown -= Time.deltaTime;
        }
        else
        {
            _cooldown = 0f;
        }
    }
Пример #6
0
    IEnumerator PlayTurnRoutine()
    {
        if (gameManager != null && !gameManager.IsGameOver)
        {
            enemySensor.UpdateSensor(CurrentNode);

            yield return(new WaitForSeconds(endTurnDelay));

            Debug.Log(enemySensor.FoundPlayer);
            if (enemySensor.FoundPlayer)
            {
                gameManager.LoseLevel();

                Vector3 playerPos = board.PlayerNode.transform.position;
                enemyMover.Move(playerPos, 0f);
                while (enemyMover.IsMoving)
                {
                    yield return(null);
                }

                enemyAttack.Attack();
            }
            else
            {
                enemyMover.MoveOneTurn();
            }
        }
    }
Пример #7
0
    private IEnumerator PlayTurnRoutine()
    {
        if (m_gameManager != null)
        {
            if (!m_gameManager.IsGameOver)
            {
                m_enemySensor.UpdateSensor(m_enemyMover.CurrentNode);

                yield return(new WaitForSeconds(0.0f));

                if (m_enemySensor.FoundPlayer)
                {
                    m_gameManager.LoseLevel();

                    Vector3 playerPosition = new Vector3(m_board.PlayerNode.Coordinate.x, 0.0f, m_board.PlayerNode.Coordinate.y);
                    m_enemyMover.Move(playerPosition, 0.0f);

                    while (m_enemyMover.isMoving)
                    {
                        yield return(null);
                    }

                    m_enemyAttack.Attack();
                }
                else
                {
                    m_enemyMover.MoveOneTurn();
                }
            }
        }
    }
Пример #8
0
    IEnumerator PlayTurnRoutine()
    {
        if (m_gameManager != null && m_gameManager.IsGameOver)
        {
            // detect player
            m_enemySensor.UpdateSensor(m_enemyMover.CurrentNode);

            // wait
            yield return(new WaitForSeconds(0f));

            if (m_enemySensor.FoundPlayer)
            {
                // notify the GameManager to lose the level
                m_gameManager.LoseLevel();

                Vector3 playerPosition = new Vector3(m_board.PlayerNode.Coordinate.x, 0f,
                                                     m_board.PlayerNode.Coordinate.y);

                m_enemyMover.Move(playerPosition, 0f);

                while (m_enemyMover.isMoving)
                {
                    yield return(null);
                }

                // attack player
                m_enemyAttack.Attack();
            }
            else
            {
                //movement
                m_enemyMover.MoveOneTurn();
            }
        }
    }
Пример #9
0
 void Attack(Vector3 location)
 {
     if (attack != null)
     {
         attack.Attack();
     }
 }
Пример #10
0
    IEnumerator PlayTurnRoutine()
    {
        if (_gameManager != null && !_gameManager.IsGameOver)
        {
            //detect player
            _enemySensor.UpdateSensor(_enemyMover.CurrentNode);

            //wait
            yield return(new WaitForSeconds(0f));

            if (_enemySensor.FoundPlayer)
            {
                //notify GameManager to lose event
                _gameManager.LoseLevel();

                Vector3 playerPosition = _board.PlayerNode.coordinate;
                _enemyMover.Move(playerPosition);

                while (_enemyMover.isMoving)
                {
                    yield return(null);
                }
                //attack player
                _enemyAttack.Attack();
            }
            else
            {
                //move
                _enemyMover.MoveOneTurn();
            }
        }
    }
Пример #11
0
    IEnumerator PlayerTurnRoutine()
    {
        if (m_gameManager != null && !m_gameManager.IsGameOver)
        {
            m_enemyEye.UpdateEye();
            yield return(new WaitForSeconds(0f));

            if (m_enemyEye.FoundPlayer)
            {
                m_gameManager.LoseLevel();
                Vector3 playerPos = new Vector3(m_board.PlayerNode.Coordinate.x, 0f, m_board.PlayerNode.Coordinate.y);
                m_enemyMovement.Move(playerPos, 0f);

                while (m_enemyMovement.isMove)
                {
                    yield return(null);
                }

                m_enemyAttack.Attack();
            }
            else
            {
                m_enemyMovement.MoveOneTurn();
            }
        }
    }
Пример #12
0
    private IEnumerator <float> StartAttackRoutine()
    {
        yield return(Timing.WaitForSeconds(stats.tellTimer));

        attack.Attack();

        yield return(Timing.WaitForSeconds(stats.actionRechargeTime));

        Timing.RunCoroutine(StartAttackRoutine());
    }
Пример #13
0
    public void Mummy1stBehaviour()
    {
        if (enemyDamage.frozen == true)
        {
            agent.Stop();
            animator.enabled = false;
        }
        else if (enemyDamage.frozen == false)
        {
            agent.Resume();
            animator.enabled = true;
        }

        float distance = Vector3.Distance(target.transform.position, transform.position);

        //When the prey is within the enemy field of view, the enemy will chase it
        if (distance <= lookRadius)
        {
            //Always look at the prey if i can see him
            if (enemyDamage.health > 0)
            {
                transform.LookAt(target.transform);
            }
            agent.SetDestination(target.transform.position);
        }

        if (!agent.pathPending)
        {
            if (agent.remainingDistance <= agent.stoppingDistance)
            {
                if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
                {
                    animator.SetFloat("Speed", 0f);
                    enemyAttack.Attack();
                }
            }
        }
        else
        {
            animator.SetFloat("Speed", 0.2f);
        }
    }
Пример #14
0
    public override IEnumerator Action()
    {
        var wait = new WaitForSeconds(1f);

        if (!isSetuna && !SceneChanger.Instance().isChanging)
        {
            AudioManager.Instance.PlayEnemySE(AudioName.oni_oaa_preAttack_03.String());
            yield return(wait);
        }
        yield return(enemyAttack.Attack());
    }
Пример #15
0
    private IEnumerator AttackRoutine()
    {
        Animator.SetTrigger("AttackStart");
        OnAttackStart.Invoke();
        _attackCooldown = 3f;
        yield return(new WaitForSeconds(AttackDelay));

        Animator.SetTrigger("Attack");
        _enemyAttack.Attack();
        OnAttack.Invoke();
    }
Пример #16
0
 private void Update()
 {
     if (movement.DistanceToTarget <= attack.attackRange)
     {
         attack.Attack();
     }
     else
     {
         movement.Move();
     }
 }
Пример #17
0
    void Update()
    {
        switch (currentState)
        {
        case EnemyState.Idle:
            if (canIdle)
            {
                enemyIdle.Idle();
            }
            else
            {
                SwitchCurrentState("Moving");
            }
            break;

        case EnemyState.Moving:
            if (canMove)
            {
                enemyMovement.UseMovement();
            }
            else
            {
                SwitchCurrentState("Idle");
            }
            break;

        case EnemyState.Death:
            enemyDeath.Death();
            break;

        case EnemyState.Hurt:
            break;

        case EnemyState.Attack:
            if (canAttack)
            {
                enemyAttack.Attack();
            }
            else
            {
                SwitchCurrentState("Moving");
            }

            break;

        case EnemyState.Falling:

            break;

        default:
            break;
        }
    }
Пример #18
0
 public void Handle()
 {
     if (_agentContext.DistanceToPlayer > _attack.AttackDistance)
     {
         _stateMachine.Enter <ChaseState>();
     }
     else
     {
         _attack.VectorToPlayer = _agentContext.VectorToPlayer;
         _attack.Attack();
     }
 }
    private void FixedUpdate()
    {
        switch (state)
        {
        case State.Roaming:
            enemyMovements.MoveTo(roamingPosition);

            distance = Vector3.Distance(transform.position, roamingPosition);
            if (distance < 3f || !isMoving)
            {
                roamingPosition = GetRoamingPosition();
            }

            FindTarget();
            CheckMovements();
            break;

        case State.ChaseTarget:
            anim.SetBool("isAttacking", false);
            enemyAttack.Aim();
            enemyMovements.MoveTo(PlayerController.Instance.GetPosition());

            if (Vector3.Distance(transform.position, PlayerController.Instance.GetPosition()) < enemyAttack.GetAttackRange())
            {
                state = State.AttackTarget;
            }
            else if (Vector3.Distance(transform.position, PlayerController.Instance.GetPosition()) > stopChaseRange)
            {
                state = State.Roaming;
            }

            break;

        case State.AttackTarget:
            enemyAttack.Aim();
            enemyAttack.Attack();
            anim.SetBool("isAttacking", true);
            if (Vector3.Distance(transform.position, PlayerController.Instance.GetPosition()) > enemyAttack.GetAttackRange())
            {
                enemyAttack.ResetAttack();
                state = State.ChaseTarget;
            }
            if (health < maxHealth / 2)
            {
                anim.SetBool("isAngry", true);
            }
            break;

        case State.Dead:
            break;
        }
    }
Пример #20
0
    /// <summary>
    /// Switch the current behavior
    /// </summary>
    /// <param name="next">Behavior to switch to</param>
    public void SwitchState(State next)
    {
        switch (next)
        {
        case (State.ATTACK):
            StartCoroutine(attack.Attack());
            break;

        case (State.SEEK):
            StartCoroutine(seek.Seek());
            break;
        }
    }
Пример #21
0
    private IEnumerator <float> StartAttackRoutine()
    {
        yield return(Timing.WaitForSeconds(stats.actionRechargeTime));

        movement.Move(GameManager.instance.player.transform.position);

        yield return(Timing.WaitForSeconds(stats.tellTimer));

        attack.Attack();

        yield return(Timing.WaitForSeconds(stats.actionRechargeTime));

        Timing.RunCoroutine(StartAttackRoutine());
    }
Пример #22
0
    IEnumerator PlayTurnRoutine()
    {
        if (m_gameManager != null && !m_gameManager.IsGameOver)
        {
            m_enemySensor.UpdateSensor();

            yield return(new WaitForSeconds(0f));

            if (m_enemySensor.FoundPlayer)
            {
                if (godMode == null || (godMode != null && !godMode.IsGodModeActive))
                {
                    m_gameManager.LoseLevel();
                }

                Vector3 playerPosition = new Vector3(m_board.PlayerNode.Coordinate.x, 0f, m_board.PlayerNode.Coordinate.y);
                m_enemyMover.Move(playerPosition, 0f);

                while (m_enemyMover.isMoving)
                {
                    yield return(null);
                }
                if (godMode == null || (godMode != null && !godMode.IsGodModeActive))
                {
                    m_enemyAttack.Attack();
                }
                if (godMode != null && godMode.IsGodModeActive)
                {
                    m_enemyMover.Stand();
                }
            }
            else
            {
                m_enemyMover.MoveOneTurn();
            }
        }
    }
Пример #23
0
    /// <summary>
    /// Switch the current behavior
    /// </summary>
    /// <param name="next">Behavior to switch to</param>
    public void SwitchState(State next)
    {
        switch (next)
        {
        case (State.ATTACK):
            Debug.Log(gameObject.name + " is attacking.");
            StartCoroutine(attack.Attack());
            break;

        case (State.SEEK):
            Debug.Log(gameObject.name + " is seeking.");
            StartCoroutine(seek.Seek());
            break;
        }
    }
Пример #24
0
 void CollidedWithEnemy(EnemyAttack enemy)
 {
     enemy.Attack(this);
     if (health <= 0)
     {
         if (enemy.tag == "Dog")
         {
             PlayerDeadDog();
         }
         else
         {
             PlayerDeadMan();
         }
         Invoke("Respawn", 3);
     }
 }
Пример #25
0
    public virtual IEnumerator Kill()
    {
        gameManager.LoseLevel();

        var playerPos = new Vector3(board.PlayerNode.Coordinate.x, 0f,
                                    board.PlayerNode.Coordinate.y);

        enemyMover.Move(playerPos, 0f);

        while (enemyMover.IsMoving)
        {
            yield return(null);
        }

        enemyAttack.Attack();
    }
Пример #26
0
    private IEnumerator <float> AttackRoutine()
    {
        inPlayerRange = true;
        attack.Attack();

        yield return(Timing.WaitForSeconds(stats.actionRechargeTime));

        if (Vector2.Distance(t.position, GameManager.instance.player.transform.position) > stats.attackRange)
        {
            inPlayerRange = false;
        }
        else
        {
            Timing.RunCoroutine(AttackRoutine());
        }
    }
Пример #27
0
    private IEnumerator <float> StartEnemyCoroutine()
    {
        yield return(Timing.WaitForSeconds(stats.tellTimer));

        attack.Attack();

        if (Vector2.Distance(GameManager.instance.player.transform.position, t.position) < evadingRange)
        {
            yield return(Timing.WaitForSeconds(stats.tellTimer));

            movement.Move(GameManager.instance.player.transform.position);
        }

        yield return(Timing.WaitForSeconds(stats.actionRechargeTime));

        Timing.RunCoroutine(StartEnemyCoroutine());
    }
Пример #28
0
 void Chase()
 {
     Xdif            = Player.x - transform.position.x; //diff of xvalue
     Ydif            = Player.y - transform.position.y; //diff of yvalue
     PlayerDirection = new Vector2(Xdif, Ydif);
     if (!Physics2D.Raycast(transform.position, PlayerDirection, .2f, wall) && distance > .3f)
     {
         rb.AddForce(PlayerDirection.normalized * speed);
         anim.SetBool("is_walking", true);
         anim.SetFloat("input_x", PlayerDirection.x);
         anim.SetFloat("input_y", PlayerDirection.y);
     }
     else
     {
         anim.SetBool("is_walking", false);
         enemyAttack.Attack();
     }
 }
Пример #29
0
    /* Mobile Clic
     * void Move (float h, float v) {
     *      float step = speed * Time.deltaTime;
     *      transform.position = Vector3.MoveTowards(transform.position, new Vector3(h, 0, v), step);
     * }
     *
     * void Animate () {
     *      animator.SetBool ("IsWalking", move);
     * }
     */
    /* PC
     * void Move (float h, float v) {
     * movement.Set (h, 0f, v);
     *
     *      movement = movement.normalized * speed * Time.deltaTime;
     *      playerRigidbody.MovePosition (transform.position + movement);
     * }
     *
     * void Animate (float h, float v) {
     *      bool walking = h != 0f || v != 0f ;
     *      animator.SetBool ("IsWalking", walking);
     * }
     *
     * void Turning(float h, float v) {
     *      if (h < 0f) { //haut
     *  transform.forward = new Vector3(-1f, 0f, 0f);
     *  //transform.rotation = Quaternion.AngleAxis(-90f, new Vector3(0, 1, 0));
     *      } else if (h > 0f) { //bas
     *  transform.forward = new Vector3(1f, 0f, 0f);
     *  //transform.rotation = Quaternion.AngleAxis(90f, new Vector3(0, 1, 0));
     *      } else if (v < 0f) { //droite
     *  transform.forward = new Vector3(0f, 0f, -1f);
     *  //transform.rotation = Quaternion.AngleAxis(180f, new Vector3(0, 1, 0));
     *      } else if (v > 0f) { //gauche
     *  transform.forward = new Vector3(0f, 0f, 1f);
     *  //transform.rotation = Quaternion.AngleAxis(0f, new Vector3(0, 1, 0));
     *      }
     * }*/

    /* Mobile
     * void Turning(float h, float v) {
     *      transform.forward = new Vector3 ((transform.position.x - h) / transform.position.x, 0f, (transform.position.z - v) / transform.position.z);
     * }*/

    void triggerEnemyAttack()
    {
        Collider[] hitColliders = Physics.OverlapSphere(gameObject.transform.position, 1.3f);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            if (hitColliders[i].tag == "Enemy")
            {
                Vector3 toTarget = (gameObject.transform.position - hitColliders[i].transform.position).normalized;
                if (Vector3.Dot(toTarget, hitColliders[i].transform.forward) > 0 && Vector3.Dot(toTarget, hitColliders[i].transform.forward) < 1f)
                {
                    EnemyAttack attack = hitColliders[i].GetComponent <EnemyAttack>();
                    attack.Attack();
                }
            }
            i++;
        }
    }
Пример #30
0
    // Update is called once per frame
    void Update()
    {
        playerTransform = tPlayer.transform;
        float distance = Vector3.Distance(playerTransform.position, transform.position);

        if (distance <= fAlertRad)
        {
            nAgent.SetDestination(playerTransform.position);
            aEnemyAnim.SetInteger("RunForward", 1);
            if (nAgent.remainingDistance < 4f)
            {
                aEnemyAnim.SetInteger("RunForward", 0);
                enemyAttack.Attack();
            }
            FaceTarget();
        }
        else
        {
            nAgent.SetDestination(transform.position);
            aEnemyAnim.SetInteger("RunForward", 0);
        }
    }
Пример #31
0
    // Update is called once per frame
    void Update()
    {
        objectTarget = GameObject.FindGameObjectWithTag("Player");
        if(objectTarget.name == "FirstPersonFab(Clone)"|| objectTarget.name == "FirstPersonFab"){
            found = true;
        }
        else{
            return;
        }
        if(found == true){
        target = objectTarget.transform;
        at = GetComponent<EnemyAttack>();
        float distance = Vector3.Distance(transform.position,target.transform.position);
        if (distance <= ShootRange * 2)
            isFollow = true;
            isAttack = false;

        if (distance <= ShootRange)	{
            isFollow = false;
            isAttack = true;

        }
            if (isFollow == true){
            Follow();
        }
        if (isAttack == true){
            at.Attack(isAttack);
            //transform.position = targetpos;
            Transform x = transform;
            x.LookAt(target.position);
            Speed = 1;

        }

        }
    }