Ejemplo n.º 1
0
    IEnumerator LaunchAttack()
    {
        //if (unit.enemy.transform.position.x - gameObject.transform.position.x > 0) {
        //    enemyDirection = Direction.right;
        //} else {
        //    enemyDirection = Direction.left;
        //}
        unit.launchingAttack = true;
        Vector2 current = gameObject.transform.position;
        //todo: get direction needs to be updated when chasing from behind
        Vector2 newPosition = unit.GetFaceDirection().normalized *attackDistance + current;

        if (gameObject != null)
        {
            PetUtility.Coroutine(PetUtility.LinearMove(current, newPosition, 0.15f, gameObject.transform));
        }
        yield return(new WaitForSeconds(0.15f));

        if (gameObject != null)
        {
            PetUtility.Coroutine(PetUtility.LinearMove(newPosition, current, 0.15f, gameObject.transform));
        }
        yield return(new WaitForSeconds(0.15f));

        yield return(null);
    }
Ejemplo n.º 2
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Vector2      direction = unit.GetFaceDirection();
        Vector2      target    = direction.normalized;
        RaycastHit2D hit;
        int          layerMask = LayerMask.GetMask(iAmPet ? "Ghost" : "Pet");

        hit = Physics2D.Raycast(unit.transform.position, target, unit.attackRange, layerMask);
        if (hit)
        {
            animator.SetBool("EnemySpoted", true);
            unit.enemy = hit.collider.gameObject;
        }
        else
        {
            animator.SetBool("EnemySpoted", false);
            unit.enemy = null;
        }
    }
Ejemplo n.º 3
0
    private void Check()
    {
        Vector2      direction = unit.GetFaceDirection();
        Vector2      target    = direction.normalized;
        RaycastHit2D hit;
        int          layerMask = LayerMask.GetMask(iAmPet ? "Ghost" : "Pet");

        hit = Physics2D.Raycast(unit.transform.position, target, unit.attackRange, layerMask);
        if (hit)
        {
            unit.enemyInRange = true;
            unit.enemy        = hit.collider.gameObject;
        }
        else
        {
            unit.enemyInRange = false;
            //unit.enemy = null;
        }
    }
Ejemplo n.º 4
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //    timer -= Time.deltaTime;
    //    if (timer <= 0) {
    //        newBullet = Instantiate(bullet.gameObject, unit.GetShootPosition(), Quaternion.identity);
    //        newBullet.GetComponent<Bullet>().Initialize(unit.damage, unit.bulletVelocity, unit.GetFaceDirection());
    //        timer = attackInterval;
    //    }
    //}

    protected override void Attack()
    {
        newBullet = Instantiate(bullet.gameObject, myUnit.GetShootPosition(), Quaternion.identity);
        newBullet.GetComponent <Bullet>().Initialize(myUnit.damage, myUnit.bulletVelocity, myUnit.GetFaceDirection(), myUnit.enemy.GetComponent <UnitBehaviour>());
    }