// Use this for initialization void Start() { waitTime = 0.02f; scene = Singleton_Service.GetSingleton <SceneController>(); player = Singleton_Service.GetSingleton <Player>(); rightHand = Singleton_Service.GetSingleton <RightHand>(); leftHand = Singleton_Service.GetSingleton <LeftHand>(); music = Singleton_Service.GetSingleton <GameMusic>(); swordSource = rightHand.GetSword().GetComponent <AudioSource>(); swordAud = rightHand.GetSword().GetComponent <SwordAudio>(); shieldSource = leftHand.GetShield().GetComponent <AudioSource>(); shieldAud = leftHand.GetShield().GetComponent <ShieldAudio>(); playerHitSource = player.GetComponent <AudioSource>(); playerHitAud = player.GetComponent <PlayerHitAudio>(); playerAttack = player.GetAttack(); playerDefense = player.GetDefense(); anim = GetComponent <Animator>(); UpdateEnemyUI(); EnemyInit(); StartCoroutine("Updating"); currentState = idleState; currentState.StartState(); }
// Start is called before the first frame update void Start() { GameObject[] destination = GameObject.FindGameObjectsWithTag("Dest"); patrolDestiantion = destination[Random.Range(0, destination.Length)].GetComponent <Transform>(); currentState = Enemy_State.PATROL; }
public IEnumerable EnemyChase() { while (currentState == Enemy_State.CHASE) { checkMyVision.sensitivity = CheckMyVision.Sensitivity.LOW; agent.isStopped = false; agent.SetDestination(checkMyVision.lastKnownSighting); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance <= agent.stoppingDistance) { agent.isStopped = true; if (!checkMyVision.TargetInSight) { currentState = Enemy_State.PATROL; } else { currentState = Enemy_State.ATTACK; } yield break; } yield return(null); } }
//on collision destroy the bullet Clone void OnCollisionEnter2D(Collision2D OnHit) { if (OnHit.gameObject.tag == "Pickup") { Physics2D.IgnoreCollision(OnHit.collider, this.gameObject.GetComponent <Collider2D>()); } if (OnHit.gameObject.tag == "Enemy" || OnHit.gameObject.tag == "Boss" || OnHit.gameObject.tag == "MommaSpider") { ES = OnHit.gameObject.GetComponent <Enemy_State> (); } if (OnHit.gameObject.tag == "Player") { PS.playerHealth -= (dmg - PS.resistance); Destroy(this.gameObject); } else if (OnHit.gameObject.tag == "Enemy" || OnHit.gameObject.tag == "Boss" || OnHit.gameObject.tag == "MommaSpider") { ES.enemyHealth -= (dmg - ES.getResist()); anim = OnHit.gameObject.GetComponent <Animator>(); if (anim) { anim.SetTrigger("Hit"); } Destroy(this.gameObject); } else { Destroy(this.gameObject); } ES = null; }
void LateUpdate() { if (enemyHealth.currentHealth <= 0) { Enemy_s = Enemy_State.Dead; } // If the enemy and the player have health left... if (Enemy_s != Enemy_State.Dead) { if (enemyHealth.currentHealth <= enemyHealth.startingHealth * 0.5f) { Enemy_s = Enemy_State.Berserker; this_trs.localScale = Vector3.one * 2; } else if (enemyHealth.currentHealth != enemyHealth.startingHealth) { Attack = true; Enemy_s = Enemy_State.chase; } //몬스터 좌표 중심으로 x+Range x-Range 반경에 플레이어가 들어오면 트루 if (!Attack) { if (this_trs.position.x - Range <= player.position.x && this_trs.position.x + Range >= player.position.x) { //몬스터 좌표 중심으로 z+Range z-Range 반경에 플레이어가 들어오면 트루 if (this_trs.position.z - Range <= player.position.z && this_trs.position.z + Range >= player.position.z) { Attack = true; Enemy_s = Enemy_State.chase; } } if (this_trs.position.x - 25 >= player.position.x || this_trs.position.x + 25 <= player.position.x &&this_trs.position.z - 25 >= player.position.z || this_trs.position.z + 25 <= player.position.z) { //일정이상 몬스터는 죽임 switch (this.gameObject.name) { case "ZomBunny(Clone)": EnemyManager.Obj_Cnt[0]--; break; case "ZomBear(Clone)": EnemyManager.Obj_Cnt[1]--; break; case "Hellephant(Clone)": EnemyManager.Obj_Cnt[2]--; break; case "FirstAid(Clone)": EnemyManager.Obj_Cnt[3]--; break; } Destroy(this.gameObject); } } } }
IEnumerator Idle() { //コルーチンは一つずつ動かす if (isCoroutine) yield break; isCoroutine = true; //次の場所を決める NextPlace = Places [Random.Range (0, 3)]; yield return new WaitForSeconds(ThinkTime);//思考間隔かもしれない //次の行動を決める int action = Random.Range(0, 2); //int action = 2; Debug.Log(action); switch (action) { case 0: state = Enemy_State.Walk; break; case 1: state = Enemy_State.Wall; break; case 2: state = Enemy_State.Wave; break; } //おんなじ場所が選ばれたら攻撃 if (NextPlace == CurrentPlace) { //距離によって攻撃方法が変わる if (state == Enemy_State.Walk) { state = Enemy_State.Shot; } } /*if (NextPlace == CurrentPlace) { //距離によって攻撃方法が変わる if (CalLength() < 20) { state = Enemy_State.Wave; } else { state = Enemy_State.Wall; } } else//動けるなら動く { state = Enemy_State.Walk; }*/ isCoroutine = false; }
public IEnumerable EnemyPatrol() { while (currentState == Enemy_State.PATROL) { checkMyVision.sensitivity = CheckMyVision.Sensitivity.HIGH; agent.isStopped = false; agent.SetDestination(patrolDestiantion.position); while (agent.pathPending) { yield return(null); } if (checkMyVision.TargetInSight) { agent.isStopped = true; currentState = Enemy_State.CHASE; yield break; } yield break; } }
void Awake() { Enemy_s = Enemy_State.Idle; // 쉬는상태 this_trs = this.transform; Attack = false; // Set up the references. player = GameObject.Find("Player").transform; playerHealth = player.GetComponent <PlayerHealth> (); enemyHealth = GetComponent <EnemyHealth> (); nav = GetComponent <NavMeshAgent> (); nav.autoBraking = true; nav.autoRepath = true; temp_Vector = this_trs.position; Move_cnt = 0; speed = nav.speed; switch (this.gameObject.name) { case "ZomBunny(Clone)": Range = 6; break; case "ZomBear(Clone)": Range = 8; break; case "Hellephant(Clone)": Range = 10; break; case "FirstAid(Clone)": Range = 0; break; } }
public IEnumerable EnemyAttack() { while (currentState == Enemy_State.ATTACK) { agent.isStopped = false; agent.SetDestination(playerTransform.position); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance > agent.stoppingDistance) { currentState = Enemy_State.CHASE; } else { //Do later playerHealth.healthPoints -= maxDamage * Time.deltaTime; } yield return(null); } yield break; }
IEnumerator Wave() { if (isCoroutine) yield break; isCoroutine = true; Block_C.StartWave(); animator.SetInteger ("Attack",1); yield return new WaitForSeconds(ThinkTime);//思考間隔かもしれない state = Enemy_State.Idle; animator.SetInteger ("Attack",0); isCoroutine = false; }
IEnumerator Walk() { if (isCoroutine) yield break; isCoroutine = true; GetComponent<MoveSmooth>().Move(NextPlace.transform.position, ecZ.GetSpeed()); animator.SetBool ("Walk",true); yield return new WaitForSeconds(ThinkTime - 1);//思考間隔かもしれない state = Enemy_State.Idle;//ブロックの生成を止める yield return new WaitForSeconds(1);//止めた後 CurrentPlace = NextPlace; animator.SetBool ("Walk",false); isCoroutine = false; }
IEnumerator Shot() { if (isCoroutine) yield break; isCoroutine = true; animator.SetInteger("Attack", 1); GameObject bullet; bullet = GameObject.Instantiate(BlockBullet); bullet.GetComponent<Attack_Parameter>().Parent = this.gameObject;//もらった親を渡しておく必要がある //弾を飛ばす処理 bullet.transform.position = transform.position + transform.TransformDirection(Vector3.forward) * 5; bullet.GetComponent<Rigidbody>().velocity = ((Player.transform.position - transform.position).normalized * bullet.GetComponent<Attack_Parameter>().speed); /*if(!audioSource.isPlaying){ audioSource.Play(); }*/ yield return new WaitForSeconds(ThinkTime);//思考間隔かもしれない Destroy(bullet); state = Enemy_State.Idle; animator.SetInteger("Attack", 0); isCoroutine = false; }