Esempio n. 1
0
    private void doAttack(DamageObject damageObject, UNITSTATE state, string inputAction)
    {
        animator.SetAnimatorTrigger(damageObject.animTrigger);
        playerState.SetState(state);

        //save attack data
        lastAttack           = damageObject;
        lastAttack.inflictor = gameObject;
        lastAttackTime       = Time.time;
        lastAttackInput      = inputAction;
        lastAttackDirection  = currentDirection;

        //turn towards current input direction
        TurnToDir(currentDirection);

        if (isGrounded)
        {
            SetVelocity(Vector3.zero);
        }
        if (damageObject.forwardForce > 0)
        {
            animator.AddForce(damageObject.forwardForce);
        }

        if (state == UNITSTATE.JUMPKICK)
        {
            return;
        }
        Invoke("Ready", damageObject.duration);
    }
Esempio n. 2
0
 public void READY()
 {
     enemyState = UNITSTATE.IDLE;
     anim.SetAnimatorTrigger("Idle");
     anim.SetAnimatorFloat("MovementSpeed", 0);
     Move(Vector3.zero, 0);
 }
Esempio n. 3
0
 public void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "Player") // 만약 충돌한 오브젝트의 태그가 플레이어라면
     {
         anime.SetBool("Move", true);
         unitstate = UNITSTATE.WALK;
     }
 }
Esempio n. 4
0
 void OnTriggerExit(Collider col)
 {
     if (col.gameObject.tag == "Player")
     {
         anime.SetBool("Move", false);
         unitstate = UNITSTATE.IDLE;
     }
 }
Esempio n. 5
0
 //Defend
 void Defend()
 {
     enemyState = UNITSTATE.DEFEND;
     animator.ShowDefendEffect();
     animator.SetAnimatorTrigger("Defend");
     GlobalAudioPlayer.PlaySFX("DefendHit");
     animator.SetDirection(currentDirection);
 }
Esempio n. 6
0
 private void DoAttack(DamageObject d, UNITSTATE state, INPUTACTION inputAction, bool returnIdle)
 {
     animator.SetAnimatorTrigger(d.animTrigger);
     playerState.SetState(state);
     lastAttack           = d;
     lastAttack.inflictor = gameObject;
     lastAttackTime       = Time.time;
     lastAttackDirection  = currentDirection;
     TurnToDir(currentDirection);
 }
Esempio n. 7
0
 //set the playerstate
 public void setPlayerState(UNITSTATE state)
 {
     if (playerState != null)
     {
         playerState.SetState(state);
     }
     else
     {
         Debug.Log("no playerState found on this gameObject");
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 设置玩家动作状态
 /// </summary>
 /// <param name="state"></param>
 public void SetPlayerState(UNITSTATE state)
 {
     if (playerState != null)
     {
         playerState.SetState(state);
     }
     else
     {
         Debug.LogError("No playerstate found on this gamaobject");
     }
 }
    void Update()
    {
        switch (unitstate)
        {
        case UNITSTATE.NONE:

            break;

        case UNITSTATE.MOVE:
            gameObject.GetComponentInChildren <Animator>().SetBool("Attack", false);
            transform.Translate(unitSpeed * Time.deltaTime, 0, 0);
            break;

        case UNITSTATE.ATTACK:
            gameObject.GetComponentInChildren <Animator>().SetBool("Attack", true);
            attackCool += Time.deltaTime;
            if (attackCool >= attackResPawn)
            {
                Instantiate(effect, transform.position, transform.rotation);
                enemy.GetComponent <EnemyController>().enemyHp -= damage;
                attackCool = 0;
            }
            break;

        case UNITSTATE.DEAD:
            transform.Translate(-unitSpeed * Time.deltaTime, 0, 0);
            gameObject.GetComponentInChildren <Animator>().SetBool("Die", true);
            Destroy(gameObject, 0.6f);
            break;

        default:
            break;
        }
        if (enemyIn == false)
        {
            unitstate = UNITSTATE.ATTACK;
            if (enemy.GetComponent <EnemyController>().enemystate == EnemyController.ENEMYSTATE.DEAD)
            {
                enemyIn = true;
            }
        }
        if (enemyIn == true)
        {
            unitstate = UNITSTATE.MOVE;
        }
        if (unitHp <= 0)
        {
            unitstate = UNITSTATE.DEAD;
        }
    }
Esempio n. 10
0
    void Damaged()
    {
        --health;
        anim["damage"].speed = 0.5f;
        anim.Play("damage");
        anim.PlayQueued("iddle", QueueMode.CompleteOthers);

        stateTime = 0.0f;
        enemyState = UNITSTATE.UNIT_IDLE;

        if(health<=0)
        {
            enemyState = UNITSTATE.UNIT_DEAD;
        }
    }
Esempio n. 11
0
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "Castle")
     {
         hpManager.GetComponent <HPManager>().castleGauge.transform.localScale -= new Vector3(damage / hpManager.GetComponent <HPManager>().castleHP *360, 0, 0);
         unitstate = UNITSTATE.DEAD;
         //unitstate = UNITSTATE.ATTACK;
     }
     if (enemyIn == true)
     {
         if (col.gameObject.tag == "Enemy1")
         {
             enemy   = col.gameObject;
             enemyIn = false;
         }
     }
 }
Esempio n. 12
0
 private void doAttack(DamageObject d, UNITSTATE state, INPUTACTION inputAction)
 {
     animator.SetAnimatorTrigger(d.animTrigger);
     playerState.SetState(state);
     lastAttack           = d;
     lastAttack.inflictor = gameObject;
     lastAttackTime       = Time.time;
     lastAttackInput      = inputAction;
     lastAttackDirection  = currentDirection;
     TurnToDir(currentDirection);
     SetVelocity(Vector3.zero);
     if (state == UNITSTATE.JUMPKICK)
     {
         return;
     }
     Invoke("Ready", d.duration);
 }
Esempio n. 13
0
    //walk to target
    public void WalkTo(float proximityRange, float movementMargin)
    {
        Vector3 dirToTarget;

        LookAtTarget(target.transform);
        enemyState = UNITSTATE.WALK;

        //clamp zspread to attackDistance when ENGAGED, otherwise we might not be able to reach the player at all
        if (enemyTactic == ENEMYTACTIC.ENGAGE)
        {
            dirToTarget = target.transform.position - (transform.position + new Vector3(0, 0, Mathf.Clamp(ZSpread, 0, attackRangeDistance)));
        }
        else
        {
            dirToTarget = target.transform.position - (transform.position + new Vector3(0, 0, ZSpread));
        }

        //we are too far away, move closer
        if (distance >= proximityRange)
        {
            moveDirection = new Vector3(dirToTarget.x, 0, dirToTarget.z);
            if (IsGrounded() && !WallSpotted() && !PitfallSpotted())
            {
                Move(moveDirection.normalized, walkSpeed);
                animator.SetAnimatorFloat("MovementSpeed", rb.velocity.sqrMagnitude);
                return;
            }
        }

        //we are too close, move away
        if (distance <= proximityRange - movementMargin)
        {
            moveDirection = new Vector3(-dirToTarget.x, 0, 0);
            if (IsGrounded() && !WallSpotted() && !PitfallSpotted())
            {
                Move(moveDirection.normalized, walkBackwardSpeed);
                animator.SetAnimatorFloat("MovementSpeed", -rb.velocity.sqrMagnitude);
                return;
            }
        }

        //otherwise do nothing
        Move(Vector3.zero, 0f);
        animator.SetAnimatorFloat("MovementSpeed", 0);
    }
Esempio n. 14
0
    /// <summary>
    /// 移动到目标
    /// </summary>
    /// <param name="proximityRange">距离范围</param>
    /// <param name="movementMargin"></param>
    public void WalkTo(float proximityRange, float movementMargin)
    {
        Vector3 dirToTarget;

        LookAtTarget(target.transform);
        enemyState = UNITSTATE.WALK;

        //判读距离
        if (enemyTactic == ENEMYTACTIC.ENGAGE)
        {
            dirToTarget = target.transform.position - (transform.position + new Vector3(0, 0, Mathf.Clamp(ZSpread, 0, attackRangeDistance)));
        }
        else
        {
            dirToTarget = target.transform.position - (transform.position + new Vector3(0, 0, ZSpread));
        }

        //太远
        if (distance >= proximityRange)
        {
            moveDirection = new Vector3(dirToTarget.x, 0, dirToTarget.z);
            if (IsGrounded() && !WallSpotted() && !PitfallSpotted())
            {
                Move(moveDirection.normalized, walkSpeed);
                animator.SetAnimatorFloat("MovementSpeed", rb.velocity.sqrMagnitude);
                return;
            }
        }

        //太近
        if (distance <= proximityRange - movementMargin)
        {
            moveDirection = new Vector3(-dirToTarget.x, 0, 0);
            if (IsGrounded() && !WallSpotted() && !PitfallSpotted())
            {
                Move(moveDirection.normalized, walkBackwardSpeed);
                animator.SetAnimatorFloat("MovementSpeed", -rb.velocity.sqrMagnitude);
                return;
            }
        }

        //什么也不做
        Move(Vector3.zero, 0f);
        animator.SetAnimatorFloat("MovementSpeed", 0);
    }
Esempio n. 15
0
    //we are hit  被攻击
    public void Hit(DamageObject d)
    {
        //Camera Shake
        CamShake camShake = Camera.main.GetComponent <CamShake>();

        if (camShake != null)
        {
            camShake.Shake(.2f);
        }

        //check for hit
        anim.SetAnimatorTrigger("Hit1");
        enemyState = UNITSTATE.HIT;

        //add small force from the impact
        LookAtTarget(d.inflictor.transform);
        anim.AddForce(-knockbackForce);
    }
Esempio n. 16
0
    //Attack
    public void ATTACK()
    {
        //don't attack when player is jumping
        var playerMovement = target.GetComponent <PlayerMovement>();

        if (!AttackPlayerAirborne && playerMovement != null && playerMovement.jumpInProgress)
        {
            return;
        }
        else
        {
            //init
            enemyState = UNITSTATE.ATTACK;
            Move(Vector3.zero, 0f);
            LookAtTarget(target.transform);
            TurnToDir(currentDirection);

            //pick random attack
            if (PickRandomAttack)
            {
                AttackCounter = Random.Range(0, AttackList.Length);
            }

            //play animation
            animator.SetAnimatorTrigger(AttackList[AttackCounter].animTrigger);

            //go to the next attack in the list
            if (!PickRandomAttack)
            {
                AttackCounter += 1;
                if (AttackCounter >= AttackList.Length)
                {
                    AttackCounter = 0;
                }
            }

            lastAttackTime       = Time.time;
            lastAttack           = AttackList [AttackCounter];
            lastAttack.inflictor = gameObject;

            //resume
            Invoke("Ready", AttackList [AttackCounter].duration);
        }
    }
Esempio n. 17
0
    /// <summary>
    /// 攻击
    /// </summary>
    public void ATTACK()
    {
        //print("gongji ");
        var playerMovement = target.GetComponent <PlayerMovement>();

        if (!attackPlayerAirborne && playerMovement != null && playerMovement.jumpInProgress)
        {
            return;
        }
        else
        {
            enemyState = UNITSTATE.ATTACK;
            Move(Vector3.zero, 0f);
            LookAtTarget(target.transform);
            TurnToDir(currentDirection);

            if (pickRandomAttack)
            {
                attackCounter = Random.Range(0, attackList.Length);
            }

            anim.SetAnimatorTrigger(attackList[attackCounter].animTrigger);

            if (!pickRandomAttack)
            {
                attackCounter += 1;
                if (attackCounter >= attackList.Length)
                {
                    attackCounter = 0;
                }
            }

            lastAttackTime = Time.time;
            lastAttack     = attackList[attackCounter];

            Invoke("READY", attackList[attackCounter].duration);
        }
    }
Esempio n. 18
0
    /// <summary>
    /// 被攻击
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只有在第一次被击倒时才能进行地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            animator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //给敌人添加硬直时间
            lastAttackTime = Time.time;

            //在倒地状态只能被攻击一次
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //防御状态能够攻击
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //攻击声音播放
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //攻击特效
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //相机震动
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //摄像机慢动作
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少HP
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //转向攻击的方向
            int dir = d.inflictor.transform.position.x > transform.position.x? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //检测是否倒地
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //默认攻击
                int rand = Random.Range(1, 3);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //对攻击对象施加力
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //当收到攻击的时候将敌人的状态从被动切换到主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }
Esempio n. 19
0
    void Update()
    {
        if (doting == true)
        {
            poisonFire.SetActive(true);
        }



        if (Main.GetComponent <PlayerController>().hp <= 0)
        {
            if (unit != UNIT.BOSS && unit != UNIT.MIDDLEBOSS)
            {
                isDead = true;
                DeadProcess();
            }
        }

        if (hP <= 0)
        {
            hP = 0;
            hpBar[1].transform.localScale = new Vector3(0, 1, 1);
            isDead = true;



            DeadProcess();


            if (goldRate <= 19)
            {
                if (dropGold != null)
                {
                    Instantiate(dropGold, transform.position, transform.rotation);
                    MoneyManager.inStance.AssaGoldDeuck();

                    dropGold = null;
                }

                else
                {
                    dropGold = null;
                }
            }

            else
            {
                dropGold = null;
            }


            if (soulRate <= 19)
            {
                if (dropSoul != null)
                {
                    Instantiate(dropSoul, transform.position, transform.rotation);
                    MoneyManager.inStance.AssaSoulDeuck();
                    dropSoul = null;
                }

                else
                {
                    dropSoul = null;
                }
            }

            else
            {
                dropSoul = null;
            }
        }

        if (isDead == false)
        {
            switch (unitstate)
            {
            case UNITSTATE.IDLE:
                if (stun == false)
                {
                    sternEffect.SetActive(false);
                    if (look.Count == 0 || look[0] == null)
                    {
                        look.Clear();
                        unitstate = UNITSTATE.MOVE;
                    }

                    else
                    {
                        unitstate = UNITSTATE.ATTACK;
                    }
                }

                if (stun == true)
                {
                    sternEffect.SetActive(true);
                    stateTime += Time.deltaTime;
                    if (wind == true)
                    {
                        gameObject.transform.Translate(1 * Time.deltaTime, 0, 0);
                    }
                    if (stateTime > idleStateMaxTime)
                    {
                        stateTime = 0;
                        unitstate = UNITSTATE.IDLE;
                        stun      = false;
                        wind      = false;
                    }
                }

                break;

            case UNITSTATE.MOVE:
                hpBar[0].SetActive(false);
                hpBar[1].SetActive(false);
                switch (unit)
                {
                case UNIT.PLAYER:
                    anime.SetBool("Attack", false);

                    anime.SetBool("Move", true);
                    transform.Translate(speed * Time.deltaTime, 0, 0);
                    break;

                case UNIT.GUARDIAN:
                    anime.SetBool("Attack", false);
                    anime.SetBool("Move", true);
                    transform.Translate(speed * Time.deltaTime, 0, 0);
                    break;

                case UNIT.ENEMY:
                    anime.SetBool("Attack", false);
                    anime.SetBool("Move", true);
                    transform.Translate(-speed * Time.deltaTime, 0, 0);
                    break;

                case UNIT.MIDDLEBOSS:
                    anime.SetBool("Attack", false);
                    anime.SetBool("Move", true);
                    transform.Translate(-speed * Time.deltaTime, 0, 0);
                    if (gameObject.transform.position.x <= 3.5f)
                    {
                        unitstate = UNITSTATE.ATTACK;
                    }
                    break;

                case UNIT.PLAYERACHER:
                    anime.SetBool("Attack", false);
                    anime.SetBool("Move", true);
                    transform.Translate(speed * Time.deltaTime, 0, 0);
                    break;

                case UNIT.BOSS:
                    anime.SetBool("Attack", false);
                    anime.SetBool("Move", true);
                    transform.Translate(-speed * Time.deltaTime, 0, 0);
                    break;
                }

                break;

            case UNITSTATE.ATTACK:
                anime.SetBool("Move", false);
                anime.SetBool("Attack", false);

                switch (unit)
                {
                case UNIT.PLAYER:

                    if (look.Count > 0)
                    {
                        if (look[0] != null)
                        {
                            stateTime += Time.deltaTime;
                            anime.SetBool("Attack", true);
                            if (look[0].tag == "Enemy")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    look[0].GetComponent <UnitController>().GetDamage(atk);
                                }
                            }

                            if (look[0].tag == "Castle")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    look[0].GetComponent <Castle>().hp -= atk;
                                    Instantiate(effect[1], effect[1].transform.position = new Vector3(look[0].GetComponent <Castle>().transform.position.x, look[0].GetComponent <Castle>().transform.position.y, look[0].GetComponent <Castle>().transform.position.z - 1), transform.rotation);
                                }
                            }
                        }
                        else
                        {
                            look.RemoveAt(0);
                        }
                    }

                    else
                    {
                        unitstate = UNITSTATE.MOVE;
                    }

                    break;

                case UNIT.ENEMY:


                    if (look.Count > 0)
                    {
                        if (look[0] != null)
                        {
                            stateTime += Time.deltaTime;
                            anime.SetBool("Attack", true);

                            if (look[0].tag == "Player")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    look[0].GetComponent <UnitController>().GetDamage(atk);
                                }
                            }


                            if (look[0].tag == "Darking")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    look[0].GetComponent <PlayerController>().hp       -= atk;
                                    Instantiate(effect[0], effect[0].transform.position = new Vector3(look[0].GetComponent <PlayerController>().transform.position.x, look[0].GetComponent <PlayerController>().transform.position.y, look[0].GetComponent <PlayerController>().transform.position.z), transform.rotation);

                                    //float distance = Vector3.Distance(sensor.GetComponent<PlayerSensor>().playerPos.position, sensor.transform.position);

                                    float distance = sensor.GetComponent <PlayerSensor>().playerPos.position.x - sensor.transform.position.x;

                                    if (distance < -0.5f)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }

                                    if (distance > 0)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }
                                }
                            }
                        }

                        else
                        {
                            look.RemoveAt(0);
                        }
                    }

                    else
                    {
                        unitstate = UNITSTATE.MOVE;
                    }

                    break;

                case UNIT.MIDDLEBOSS:

                    stateTime += Time.deltaTime;
                    anime.SetBool("Attack", true);

                    if (sn == SomonRound[0])
                    {
                        if (stateTime > attackStateMaxTime)
                        {
                            stateTime = 0;
                            Instantiate(somon[0], transform.position, transform.rotation);
                        }
                    }

                    if (sn == SomonRound[1])
                    {
                        if (stateTime > attackStateMaxTime)
                        {
                            stateTime = 0;
                            Instantiate(somon[0], transform.position, transform.rotation);
                        }
                    }

                    break;

                case UNIT.BOSS:


                    if (look.Count > 0)
                    {
                        if (look[0] != null)
                        {
                            stateTime += Time.deltaTime;
                            anime.SetBool("Attack", true);

                            if (look[0].tag == "Player")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    //anime.SetBool("Attack", true);
                                    look[0].GetComponent <UnitController>().GetDamage(atk);
                                }
                            }


                            if (look[0].tag == "Darking")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    //anime.SetBool("Attack", true);
                                    look[0].GetComponent <PlayerController>().hp -= atk;

                                    //float distance = Vector3.Distance(sensor.GetComponent<PlayerSensor>().playerPos.position, sensor.transform.position);

                                    float distance = sensor.GetComponent <PlayerSensor>().playerPos.position.x - sensor.transform.position.x;

                                    if (distance < -1f)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }

                                    if (distance > 0)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }
                                }
                            }
                        }

                        else
                        {
                            look.RemoveAt(0);
                        }
                    }

                    else
                    {
                        unitstate = UNITSTATE.MOVE;
                    }

                    break;

                case UNIT.PLAYERACHER:

                    if (look.Count > 0)
                    {
                        if (look[0] != null)
                        {
                            stateTime += Time.deltaTime;
                            anime.SetBool("Attack", true);

                            if (look[0].tag == "Enemy")
                            {
                                //anime.SetBool("Attack", true);
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;

                                    Bullets.GetComponent <SkillController>().atk = atk;
                                    Bullets.GetComponent <SkillController>().lv  = lv;
                                    if (Bullets.name != "Guardian_Skill")
                                    {
                                        Instantiate(Bullets, transform.position, transform.rotation);
                                    }
                                    if (Bullets.name == "Guardian_Skill")
                                    {
                                        Instantiate(Bullets, Bullets.transform.position = new Vector3(transform.position.x + 0.71f, transform.position.y + 0.24f, transform.position.z + 0.3f), Bullets.transform.rotation);
                                    }
                                }
                            }

                            if (look[0].tag == "Castle")
                            {
                                //anime.SetBool("Attack", true);
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;

                                    Bullets.GetComponent <SkillController>().atk = atk;
                                    Bullets.GetComponent <SkillController>().lv  = lv;
                                    Instantiate(Bullets, transform.position, transform.rotation);
                                }
                            }
                        }
                        else
                        {
                            look.RemoveAt(0);
                        }
                    }

                    else
                    {
                        unitstate = UNITSTATE.MOVE;
                    }


                    break;


                case UNIT.ENEMYACHER:

                    if (look.Count > 0)
                    {
                        if (look[0] != null)
                        {
                            anime.SetBool("Attack", true);
                            stateTime += Time.deltaTime;

                            if (look[0].tag == "Player")
                            {
                                //anime.SetBool("Attack", true);
                                if (stateTime > attackStateMaxTime)
                                {
                                    stateTime = 0;
                                    Instantiate(Bullets, transform.position, transform.rotation);
                                }
                            }


                            if (look[0].tag == "Darking")
                            {
                                if (stateTime > attackStateMaxTime)
                                {
                                    //anime.SetBool("Attack", true);
                                    stateTime = 0;
                                    Instantiate(Bullets, transform.position, transform.rotation);

                                    //float distance = Vector3.Distance(sensor.GetComponent<PlayerSensor>().playerPos.position, sensor.transform.position);

                                    float distance = sensor.GetComponent <PlayerSensor>().playerPos.position.x - sensor.transform.position.x;

                                    if (distance < -0.5f)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }

                                    if (distance > 0)
                                    {
                                        look.RemoveAt(0);
                                        unitstate = UNITSTATE.MOVE;
                                    }
                                }
                            }
                        }

                        else
                        {
                            look.RemoveAt(0);
                        }
                    }

                    else
                    {
                        unitstate = UNITSTATE.MOVE;
                    }


                    break;
                }

                break;

            case UNITSTATE.DEAD:


                break;
            }
        }
        if (hP < maxHp)
        {
            if (isDead == false)
            {
                //hpBar[0].SetActive(true);
                //hpBar[1].SetActive(true);
                //if (hpBar[1].transform.localScale.x < 0)
                //{
                //    hpBar[1].transform.localScale = new Vector3(0, 1, 1);
                //}
                //hpBar[1].transform.localScale = new Vector3(hP / maxHp * 1, 1, 1);
            }
        }
    }
Esempio n. 20
0
 void Start()
 {
     unitstate = UNITSTATE.MOVE;
     hpManager = GameObject.Find("HPManager");
 }
Esempio n. 21
0
 void Start()
 {
     isDead    = false;
     unitstate = UNITSTATE.MOVE;
     look      = new List <GameObject>();
 }
Esempio n. 22
0
    void OnCollisionEnter(Collision collision)
    {
        int collisionLayer = collision.gameObject.layer;

        if(collisionLayer == LayerMask.NameToLayer("Missile"))
        {
            enemyState = UNITSTATE.UNIT_DAMAGED;
        }
    }
Esempio n. 23
0
    void Idle()
    {
        stateTime += Time.deltaTime;
        if(stateTime>idleStateMaxTime)
        {

            stateTime = 0.0f;
            enemyState = UNITSTATE.UNIT_MOVE;
           // stateTime = a
        }
    }
Esempio n. 24
0
    //knockDown sequence
    IEnumerator KnockDownSequence(GameObject inflictor)
    {
        enemyState = UNITSTATE.KNOCKDOWN;
        yield return(new WaitForFixedUpdate());

        //look towards the direction of the incoming attack
        int dir = 1;

        if (inflictor != null)
        {
            dir = inflictor.transform.position.x > transform.position.x? 1 : -1;
        }
        currentDirection = (DIRECTION)dir;
        animator.SetDirection(currentDirection);
        TurnToDir(currentDirection);

        //add knockback force
        animator.SetAnimatorTrigger("KnockDown_Up");
        while (IsGrounded())
        {
            SetVelocity(new Vector3(KnockbackForce * -dir, KnockdownUpForce, 0));
            yield return(new WaitForFixedUpdate());
        }

        //going up...
        while (rb.velocity.y >= 0)
        {
            yield return(new WaitForFixedUpdate());
        }

        //going down
        animator.SetAnimatorTrigger("KnockDown_Down");
        while (!IsGrounded())
        {
            yield return(new WaitForFixedUpdate());
        }

        //hit ground
        animator.SetAnimatorTrigger("KnockDown_End");
        GlobalAudioPlayer.PlaySFXAtPosition("Drop", transform.position);
        animator.SetAnimatorFloat("MovementSpeed", 0f);
        animator.ShowDustEffectLand();
        enemyState = UNITSTATE.KNOCKDOWNGROUNDED;
        Move(Vector3.zero, 0f);

        //cam shake
        CamShake camShake = Camera.main.GetComponent <CamShake>();

        if (camShake != null)
        {
            camShake.Shake(.3f);
        }

        //dust effect
        animator.ShowDustEffectLand();

        //stop sliding
        float   t            = 0;
        float   speed        = 2;
        Vector3 fromVelocity = rb.velocity;

        while (t < 1)
        {
            SetVelocity(Vector3.Lerp(new Vector3(fromVelocity.x, rb.velocity.y + Physics.gravity.y * Time.fixedDeltaTime, fromVelocity.z), new Vector3(0, rb.velocity.y, 0), t));
            t += Time.deltaTime * speed;
            yield return(new WaitForFixedUpdate());
        }

        //knockDown Timeout
        Move(Vector3.zero, 0f);
        yield return(new WaitForSeconds(KnockdownTimeout));

        //stand up
        enemyState = UNITSTATE.STANDUP;
        animator.SetAnimatorTrigger("StandUp");
        Invoke("Ready", standUpTime);
    }
Esempio n. 25
0
 void InitSpider()
 {
     enemyState = UNITSTATE.UNIT_IDLE;
     anim.Play("iddle"); // or move
 }
Esempio n. 26
0
    //Unit was hit
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //only allow ground attacks to hit us when we are knocked down
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            animator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //add attack time out so this enemy cannot attack instantly after a hit
            lastAttackTime = Time.time;

            //don't hit this unit when it's allready down
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //defend an incoming attack
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //hit sfx
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //hit particle effect
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //camera Shake
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //activate slow motion camera
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //substract health
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //ground attack
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //turn towards the direction of the incoming attack
            int dir = d.inflictor.transform.position.x > transform.position.x? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //check for a knockdown
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //default hit
                int rand = Random.Range(1, 3);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //add small force from the impact
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //switch  enemy state from passive to aggressive when attacked
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }
Esempio n. 27
0
 public void SetState(UNITSTATE state)
 {
     currentState = state;
     //print(currentState);
 }
Esempio n. 28
0
 public void SetState(UNITSTATE state)
 {
     currentState = state;
 }
Esempio n. 29
0
    void Update()
    {
        Debug.Log(target.GetComponent <Move>().playerstate);


        Debug.DrawRay(gameObject.transform.position, Vector3.left * 6f, Color.red);



        //if (Physics.Raycast(gameObject.transform.position, Vector3.left, out hit, 6f))
        //{
        //    if (hit.collider.tag == "Player")
        //    {
        //        unitstate = UNITSTATE.WALK;

        //        if (playerstate == Move.PLAYERSTATE.ATTACK)
        //        {
        //            unitstate = UNITSTATE.DAMAGE;
        //        }

        //    }
        //}


        switch (unitstate)
        {
        case UNITSTATE.IDLE:

            if (target.GetComponent <Move>().playerstate == Move.PLAYERSTATE.IDLE)
            {
                anime.SetBool("Attack", false);
                return;
            }
            else if (target.GetComponent <Move>().playerstate != Move.PLAYERSTATE.IDLE)
            {
                anime.SetBool("Move", true);
                unitstate = UNITSTATE.WALK;
            }


            break;

        case UNITSTATE.WALK:

            float distance = (target.position - transform.position).magnitude;

            if (distance <= 2f)     // 만약 타겟과의 거리가 2보다 작을 경우 어택상태로 변경한다.
            {
                anime.SetBool("Move", false);
                unitstate = UNITSTATE.ATTACK;
            }

            Vector3 dir = target.position - transform.position;
            dir.y = 0f;
            dir.Normalize();
            gameObject.transform.Translate(dir * speed * Time.deltaTime);

            break;

        case UNITSTATE.DAMAGE:
            if (hp > 0)
            {
                hp -= target.GetComponent <Move>().PlayerAtk;
                Debug.Log("적의 남은 체력 : " + hp);
                unitstate = UNITSTATE.ATTACK;
            }

            if (hp <= 0)
            {
                unitstate = UNITSTATE.DEAD;
            }
            break;

        case UNITSTATE.ATTACK:

            STATETIME += Time.deltaTime;
            if (STATETIME >= ATTACKTIME)
            {
                anime.SetBool("Attack", true);
                STATETIME = 0f;

                target.GetComponent <Move>().playerstate = Move.PLAYERSTATE.DAMAGE;

                unitstate = UNITSTATE.IDLE;
            }



            //else if (target.GetComponent<Move>().playerstate == Move.PLAYERSTATE.ATTACK)
            //{
            //    unitstate = UNITSTATE.DAMAGE;
            //}


            float distance3 = (target.position - transform.position).magnitude;
            if (distance3 >= 2f)
            {
                anime.SetBool("Move", true);
                unitstate = UNITSTATE.WALK;
            }

            //if (hit.distance <= 2f)
            //{
            //    unitstate = UNITSTATE.WALK;
            //}

            break;

        case UNITSTATE.DEAD:

            if (hp == 0)
            {
                anime.SetBool("Dead", true);
                int r = Random.Range(0, 7);
                if (r < 3)
                {
                    Debug.Log(r);
                    Instantiate(BoxPrefab, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0f), Quaternion.Euler(0, 0, 0));
                }
                Destroy(gameObject);
                door.gameObject.SetActive(true);
            }

            break;
        }
    }