예제 #1
0
    void FixedUpdate()
    {
        //Animation
        if (Input.GetAxis("Horizontal") == 0)
        {
            animator.SetTrigger("startIdle");
        }
        animator.SetFloat("direction", Input.GetAxis("Horizontal"));

        //Movement
        Move(new Vector2(Input.GetAxis("Horizontal") * MaxSpeed, Input.GetAxis("Vertical") * MaxSpeed));

        //Attacking
        attackCooldown.Update();

        if (Input.GetKeyDown(KeyCode.Z))
        {
            if (attackCooldown.Available)
            {
                GameCharacter enemy = FindGameCharInDirection(MovementDirection, attackRadius, attackDistance, "Enemy");
                if (enemy != null)
                {
                    attackCooldown.Activate();
                    enemy.SendMessage("GetHit", Damage);
                    enemy.SendMessage("DrawAggro");
                }
            }
        }
    }
예제 #2
0
    /*void TrackStillTarget()
     *  {
     *          if(!isAttacking)
     *          {
     *                  if(Mathf.Abs((this.transform.position - targetPos).x) > xMoveOffset
     || Mathf.Abs((this.transform.position - targetPos).y) > yMoveOffset)
     ||                         //this.transform.position = Vector3.MoveTowards(this.transform.position, targetPos, speed);
     ||         rigid.velocity = (targetPos - transform.position).normalized * speed;
     ||                 else
     ||     {
     ||         rigid.velocity = Vector2.zero;
     ||         StartCoroutine(AttemptAttack());
     ||     }
     ||         }
     || }*/

    void TrackMovingTarget()
    {
        Vector3 targetPos = target.transform.position;

        if ((transform.position - targetPos).magnitude >= attackDistance)
        {
            Move((targetPos - transform.position).normalized * MaxSpeed);
        }
        else
        {
            if (attackCooldown.Available)
            {
                animator.SetTrigger("startAttack");
                attackCooldown.Activate();
                target.SendMessage("GetHit", Damage);
            }
        }
    }