IEnumerator DeadProcess() { Renderer[] renderers = GetComponentsInChildren <SkinnedMeshRenderer>(); Shader transparentShader = Shader.Find("Transparent/Diffuse"); renderers[0].material.shader = transparentShader; renderers[1].material.shader = transparentShader; yield return(new WaitForSeconds(2.0f)); Color fadeOutColor = Color.white; while (fadeOutColor.a > 0.0f) { yield return(new WaitForEndOfFrame()); fadeOutColor.a -= fadeOutSpeed * Time.deltaTime; renderers[0].material.color = fadeOutColor; renderers[1].material.color = fadeOutColor; } fadeOutColor.a = 0.0f; renderers[0].material.color = fadeOutColor; renderers[1].material.color = fadeOutColor; enemyState = ENEMYSTATE.NONE; gameObject.SetActive(false); yield return(null); }
protected override void Wander() {//similar to stone face wander if (m_wanderRotate == false) { Vector3 oldWander = m_wanderTarget; m_wanderTarget = PathWanderBasic(m_wanderTarget); if (oldWander != m_wanderTarget) { m_wanderRotate = true; m_lastWanderTime = Time.time; m_waitTime = Random.Range(2.4f, 5.0f); m_state = ENEMYSTATE.IDLE; } } if (m_wanderRotate == true) { m_wanderRotate = RotateToFace(m_wanderTarget); } else { PathSteering(PathSeek(m_wanderTarget)); } }
void Dead() { anim.SetBool("dead", true); enemyState = ENEMYSTATE.NONE; StartCoroutine(DeadProcess()); }
void Move() { float distance = (target.position - transform.position).magnitude; if (distance > attackRange) { Vector3 dir = target.position - transform.position; dir.y = 0.0f; dir.Normalize(); //transform.position += dir * moveSpeed * Time.deltaTime; transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime); _agent.Resume(); _agent.updatePosition = true; _agent.SetDestination(target.position); } else { stateTime = attackStateMaxTime; enemyState = ENEMYSTATE.ATTACK; anim.SetTrigger("attack"); _agent.Stop(); _agent.updatePosition = false; } }
public Enemy(Game g, Texture2D texture, Vector2 userPosition, int framecount) : base(g, texture, userPosition, framecount) { // Need to see the Game to access Viewport enemyState = ENEMYSTATE.ALIVE; myGame = g; startPosition = userPosition; }
void getClosestEnemy() { flag = true; GameObject[] taggedEnemys = GameObject.FindGameObjectsWithTag(targetTag); float closestDistSqr = Mathf.Infinity; closestEnemy = null; foreach (GameObject taggedEnemy in taggedEnemys) { objectPos = taggedEnemy.transform.position; dist = (objectPos.x - transform.position.x); if (dist < fAttackDist && dist > 0) { closestDistSqr = dist; closestEnemy = taggedEnemy.transform; } else { state = ENEMYSTATE.ENEMYRUN; animator.SetTrigger("Run"); moveSpeed = realmoveSpeed; } } target = closestEnemy; }
public void Hurt() { // Reduce the number of hit points by one. state = ENEMYSTATE.ENEMYHURT; // animator.SetTrigger("Hurt"); HP--; }
private float m_EnemyBehaveCoolTime; // enemy behave cooltime void Start() { // init m_Player = GameObject.Find("Player"); m_EnemyBehaveCoolTime = 1; m_CurState = ENEMYSTATE.IDLE; }
protected override void Wander() {//use this for basic movement //and returning to start area Vector3 oldwander = m_wanderTarget; m_wanderTarget = PathWander(m_lastWanderTime, m_wanderTarget); if (oldwander != m_wanderTarget) { m_lastWanderTime = Time.time; if ((Vector3.Distance(transform.position, m_startPos) < 8) && (Random.Range(0, 4) == 0)) { m_state = ENEMYSTATE.IDLE; m_anima.SetBool("isMoving", false); m_idleTime = Time.time; } } PathSteering(PathSeek(m_wanderTarget)); LookAt(m_wanderTarget); if (Sight()) { m_targetAquiredTime = Time.time; m_state = ENEMYSTATE.ATTACK; } }
// random move void RandomDirection() { m_Vector.Set(0, 0, m_Vector.z); m_RandomInt = Random.Range(0, 8); switch (m_RandomInt) { case 0: m_CurState = ENEMYSTATE.UP; break; case 1: m_CurState = ENEMYSTATE.DOWN; break; case 2: m_CurState = ENEMYSTATE.RIGHT; break; case 3: m_CurState = ENEMYSTATE.LEFT; break; default: m_CurState = ENEMYSTATE.IDLE; break; } }
// enemy chase player (chase state) void ChasePlayer() { // x axis more close to player if (Mathf.Abs(m_PlayerPos.x - this.transform.position.x) > Mathf.Abs(m_PlayerPos.y - this.transform.position.y)) { if (m_PlayerPos.x - this.transform.position.x > 0) { m_CurState = ENEMYSTATE.RIGHT; } else { m_CurState = ENEMYSTATE.LEFT; } } // y axis more close to player else { if (m_PlayerPos.y - this.transform.position.y > 0) { m_CurState = ENEMYSTATE.UP; } else { m_CurState = ENEMYSTATE.DOWN; } } m_TimeCount = 0; }
void Update() { switch (enemyState) { case ENEMYSTATE.DIVING: //move enemy to player if in range if (playerInRange) { enemy.transform.position = Vector2.MoveTowards(enemy.transform.position, player.transform.position, speed * 2 * Time.deltaTime); if (hasHitPlayer) { GetComponent<Collider2D>().enabled = false; enemyState = ENEMYSTATE.PATROL; StartCoroutine(DivePlayerAgain()); } } break; case ENEMYSTATE.PATROL: //move enemy to spawn position if player out of range { enemy.transform.position = Vector2.MoveTowards(enemy.transform.position, spawnPosition, speed * Time.deltaTime); } break; } }
void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Enemy") { lookEM.Add(col.gameObject); gameObject.transform.Translate(-0.01f, 0, 0); } if (col.gameObject.tag == "Player") { //Debug.Log(col.name); lookPL.Add(col.gameObject); target2 = col.gameObject.transform; } if (col.gameObject.name == "EnemyGoal") { Enemystate = ENEMYSTATE.FINISH; gameObject.transform.Rotate(0, 180, 0); } if (col.gameObject.name == "PlayerGoal") { Btn = GameObject.FindGameObjectWithTag("Btn"); Btn.GetComponent <BtnManager>().QuestBtn[0].SetActive(true); Destroy(gameObject); } }
IEnumerator disableDodgeState(float waitTime) { yield return(new WaitForSeconds(waitTime)); rb.constraints = RigidbodyConstraints.FreezeAll; enemyState = ENEMYSTATE.Idle; }
void InitSkeleton() { Renderer[] renderers = GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (Renderer currentRenderer in renderers) { currentRenderer.material.shader = Shader.Find("Legacy Shaders/Diffuse"); } healthPoint = 5.0f; enemyState = ENEMYSTATE.IDLE; stateTime = 0.0f; GetComponent <Rigidbody>().velocity = Vector3.zero; GetComponent <Rigidbody>().useGravity = false; isKnockBackState = false; NavMeshHit hit; if (NavMesh.SamplePosition(transform.position, out hit, 99f, NavMesh.AllAreas) == true) { transform.position = hit.position; } _agent.enabled = true; }
private bool attackWhilePlayerIsgrounded = true; //only attack when the player is on the ground, and not while he's jumping public void ATTACK() { if (target == null) { SetTarget2Player(); } if (Time.time - lastAttackTime > attackInterval) { //checks if we should only attack when the player is grounded if (attackWhilePlayerIsgrounded) { if (target.GetComponent <PlayerMovement>().playerIsGrounded()) { enemyState = ENEMYSTATE.ATTACK; Move(Vector3.zero, 0); //when commented the character runs to the other side LookAtTarget(); animator.Attack1(); lastAttackTime = Time.time; } } else { enemyState = ENEMYSTATE.ATTACK; Move(Vector3.zero, 0); //when commented the character runs to the other side LookAtTarget(); animator.Attack1(); lastAttackTime = Time.time; } } }
void Awake() { anim = GetComponent <Animator>(); _agent = GetComponent <NavMeshAgent>(); _agent.enabled = false; enemyState = ENEMYSTATE.IDLE; }
private void Awake() { astarPath = new List <TileData>(); enemyState = ENEMYSTATE.IDLE; spriteRenderer = GetComponent <SpriteRenderer>(); Hp_Bar = transform.GetChild(0).gameObject; Hp_Bar_Front = transform.GetChild(0).GetChild(0).gameObject; }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { playerInRange = true; enemyState = ENEMYSTATE.DIVING; } }
void OnTriggerExit2D(Collider2D other) { if (other.tag == "Player") { playerInRange = false; enemyState = ENEMYSTATE.PATROL; } }
public Enemy(Game g, Texture2D texture, Vector2 userPosition, int framecount) : base(g,texture,userPosition,framecount) { // Need to see the Game to access Viewport enemyState = ENEMYSTATE.ALIVE; myGame = g; startPosition = userPosition; }
void onPlayerDie() { StopAllCoroutines(); this.animator.SetBool("LeeDie", true); this.animator.SetBool("Attack", false); this.animator.SetBool("Run", false); this.animator.SetBool("die", false); state = ENEMYSTATE.ENEMYRUN; }
public void EndEnemyAction() { float time = Time.fixedTime - aiActionTime; if (time > aiActionTime) { aiState = ENEMYSTATE.ACTIONSELECT; } }
IEnumerator DelayRun() { yield return(new WaitForSeconds(0.9f)); state = ENEMYSTATE.ENEMYRUN; animator.SetBool("Attack", false); animator.SetBool("Die", false); animator.SetBool("Run", false); }
void Death() { state = ENEMYSTATE.ENEMYDEATH; // Find all of the sprite renderers on this object and it's children. // SpriteRenderer[] otherRenderers = GetComponentsInChildren<SpriteRenderer>(); // moveSpeed = 0.0f; // this.collider2D.enabled = false; //animator.SetTrigger("Death"); //yield return new WaitForSeconds(0.1f); //collider.enabled = false; // Disable all of them sprite renderers. /* foreach(SpriteRenderer s in otherRenderers) * { * s.enabled = false; * }*/ // Destroy (this.gameObject.collider //Destroy (this.gameObject.rigidbody2D); // Re-enable the main sprite renderer and set it's sprite to the deadEnemy sprite. //// ren.enabled = true; //ren.sprite = deadEnemy; // Increase the score by 100 points score.score += 5000; // Set dead to true. dead = true; // Allow the enemy to rotate and spin it by adding a torque. // rigidbody2D.fixedAngle = false; // rigidbody2D.AddTorque(Random.Range(deathSpinMin,deathSpinMax)); // Find all of the colliders on the gameobject and set them all to be triggers. // Collider2D[] cols = GetComponents<Collider2D>(); // foreach(Collider2D c in cols) /* { * c.isTrigger = true; * } */ // Play a random audioclip from the deathClips array. // int i = Random.Range(0, deathClips.Length); // AudioSource.PlayClipAtPoint(deathClips[i], transform.position); // Create a vector that is just above the enemy. // Vector3 scorePos; // scorePos = transform.position; // scorePos.y += 1.5f; // Instantiate the 100 points prefab at this point. // Instantiate(hundredPointsUI, scorePos, Quaternion.identity); LoseScreeen(); }
void Dead() { anim.SetBool("dead", true); enemyState = ENEMYSTATE.NONE; StartCoroutine(DeadProcess()); target.SendMessage("ResetTarget", SendMessageOptions.DontRequireReceiver); }
void OnCollisionEnter(Collision other) { Debug.Log(other.gameObject.name); if (other.gameObject.name.Contains("tiger_idle_2") == false) { return; } enemyState = ENEMYSTATE.DAMAGE; }
public void SpecRunToTransform(Transform _t) { m_maxMoveSpeed = 20; m_moveSpeed = m_maxMoveSpeed; m_state = ENEMYSTATE.SPECIAL; if (m_anima.GetBool("isMoving") != true) { m_anima.SetBool("isMoving", true); } m_specialTarget = _t; }
protected override void Idle() { if (walkaround == true) { return; } if (IsTimerDone(m_lastWanderTime, m_waitTime)) { m_state = ENEMYSTATE.WANDER; } }
void InitZombie() { if (characterController != null) { characterController.enabled = true; } healthPoint = 5; enemyState = ENEMYSTATE.IDLE; PlayIdleAnim(); }
void Update() { switch (enemystate) { case ENEMYSTATE.NONE: gameObject.GetComponentInChildren <Animator>().SetBool("Attack", false); transform.Translate(-enemySP * Time.deltaTime, 0, 0); break; case ENEMYSTATE.ATTACK: gameObject.GetComponentInChildren <Animator>().SetBool("Attack", true); attackTime += Time.deltaTime; if (attackTime >= attackResPawnTime) { Instantiate(effect, transform.position, transform.rotation); unit.GetComponent <UnitController>().unitHp -= damage; attackTime = 0; } break; case ENEMYSTATE.DEAD: transform.Translate(enemySP * Time.deltaTime, 0, 0); gameObject.GetComponentInChildren <Animator>().SetBool("Die", true); Destroy(gameObject, 0.6f); break; default: break; } if (unitIn == false) { enemystate = ENEMYSTATE.ATTACK; if (unit.GetComponent <UnitController>().unitstate == UnitController.UNITSTATE.DEAD) { unitIn = true; } } if (unitIn == true) { enemystate = ENEMYSTATE.NONE; } if (gameObject.transform.position.x <= -1.8f) { Destroy(gameObject); } if (enemyHp <= 0) { enemystate = ENEMYSTATE.DEAD; } }
void OnTriggerExit(Collider col) { if (col.gameObject.tag == "Enemy") { //Debug.Log(col.name); lookEM.Remove(col.gameObject); Enemystate = ENEMYSTATE.MOVE; } if (col.gameObject.tag == "Player") { //Debug.Log(col.name); lookPL.Remove(col.gameObject); } }
void Damage() { healthPoint -= 1; anim["damage"].speed = 0.5f; anim.Play("damage"); anim.PlayQueued("iddle", QueueMode.CompleteOthers); stateTime = 0.0f; enemyState = ENEMYSTATE.IDLE; if(healthPoint <= 0) { enemyState = ENEMYSTATE.DEAD; } }
void OnCollisionEnter(Collision other) { if (enemyState == ENEMYSTATE.DEAD || enemyState == ENEMYSTATE.NONE) { return; } if (other.gameObject.CompareTag("Ball") == false) { //if (other.gameObject.tag != "Ball") return; } enemyState = ENEMYSTATE.DAMAGE; }
public void EnemyInit() { enemyData.position.PosX = (int)this.gameObject.transform.position.x; enemyData.position.PosY = (int)this.gameObject.transform.position.y; astarPath = new List <TileData>(); enemyState = ENEMYSTATE.IDLE; spriteRenderer = GetComponent <SpriteRenderer>(); Hp_Bar_Front = transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <Image>(); TileManager.Instance.tileMapInfoArray[enemyData.position.PosX, enemyData.position.PosY].tileData.tileRestriction = TILE_RESTRICTION.OCCUPIED; //꼭 필요할까 mapWidth = TileManager.Instance.mapWidth; mapHeight = TileManager.Instance.mapHeight; }
void Idle() { stateTime += Time.deltaTime; if (stateTime > idleStateMaxTime) { stateTime = 0.0f; enemyState = ENEMYSTATE.MOVE; anim.SetTrigger("move"); } float distance = (target.position - transform.position).magnitude; if (distance <= attackRange) { stateTime = attackStateMaxTime; enemyState = ENEMYSTATE.ATTACK; anim.SetTrigger("attack"); } }
void Attack() { stateTime += Time.deltaTime; float distance = (target.position - transform.position).magnitude; if(stateTime > attackStateMaxTime) { stateTime = 0.0f; anim.Play("attack_Melee"); target.GetComponent<PlayerState>().DamageByEnemy(); anim.PlayQueued("iddle", QueueMode.CompleteOthers); } if(distance >= attackRange) { stateTime = 0.0f; enemyState = ENEMYSTATE.IDLE; } }
public override void Update(GameTime gametime) { switch (enemyState) { case ENEMYSTATE.ALIVE: break; case ENEMYSTATE.DYING: countDown --; if(countDown < 0) enemyState = ENEMYSTATE.DEAD; break; case ENEMYSTATE.DEAD: countDown = 100; Visible=false; break; } base.Update(gametime); }
void Damage() { enemyState = ENEMYSTATE.IDLE; }
void Attack() { stateTime += Time.deltaTime; if (stateTime > attackStateMaxTime) { stateTime = -attackClip.length; // attack motion time anim.SetTrigger("attack"); } float distance = (target.position - transform.position).magnitude; if (distance > attackRange) { stateTime = 0.0f; enemyState = ENEMYSTATE.IDLE; } }
void OnCollisionEnter(Collision collision) { if(collision.gameObject.name.Contains("Ball") == false) { return; } enemyState = ENEMYSTATE.DAMAGE; }
void Idle() { stateTime += Time.deltaTime; if(stateTime > idleStateMaxTime) { stateTime = 0.0f; enemyState = ENEMYSTATE.MOVE; } }
void Move() { anim.Play("walk"); float distance = (target.position - transform.position).magnitude; if(distance < attackRange) { enemyState = ENEMYSTATE.ATTACK; stateTime = attackStateMaxTime; } else { Vector3 dir = target.position - transform.position; dir.y = 0.0f; dir.Normalize(); characterController.SimpleMove(dir * moveSpeed); transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime); } }
public void die() { enemyState = ENEMYSTATE.DYING; }
public void OnDamage() { --healthPoint; if (healthPoint > 0) { enemyState = ENEMYSTATE.DAMAGE; anim.SetFloat("damage", Random.Range(1f, 2f)); } else { enemyState = ENEMYSTATE.DEAD; } damageParticle.SetActive(true); }
void Dead() { anim.SetBool("dead", true); enemyState = ENEMYSTATE.NONE; StartCoroutine( DeadProcess() ); }
IEnumerator DeadProcess() { Renderer[] renderers = GetComponentsInChildren<SkinnedMeshRenderer>(); Shader transparentShader = Shader.Find("Transparent/Diffuse"); renderers[0].material.shader = transparentShader; renderers[1].material.shader = transparentShader; yield return new WaitForSeconds(2.0f); Color fadeOutColor = Color.white; while (fadeOutColor.a > 0.0f) { yield return new WaitForEndOfFrame(); fadeOutColor.a -= fadeOutSpeed * Time.deltaTime; renderers[0].material.color = fadeOutColor; renderers[1].material.color = fadeOutColor; } fadeOutColor.a = 0.0f; renderers[0].material.color = fadeOutColor; renderers[1].material.color = fadeOutColor; enemyState = ENEMYSTATE.NONE; gameObject.SetActive(false); yield return null; }
void InitSpider() { enemyState = ENEMYSTATE.IDLE; anim.Play("iddle"); }
void Awake() { anim = GetComponent<Animator>(); enemyState = ENEMYSTATE.IDLE; }
// Use this for initialization void Awake() { m_Controller = GetComponent<CharacterController>(); m_AnimationManager = gameObject.GetComponent<AnimationManagerEnemy>(); m_NextState = ENEMYSTATE.ES_IDLE; m_TempVec3 = new Vector3(); m_Dir = new Vector3(); m_SelectedPlane = transform.FindChild("SelectedPlane").gameObject; m_SelectedPlane.SetActive(false); m_HitObj = transform.FindChild("HitObj").gameObject; _InitData(); }
void Move() { float distance = (target.position - transform.position).magnitude; if (distance > attackRange) { Vector3 dir = target.position - transform.position; dir.y = 0.0f; dir.Normalize(); transform.position += dir * moveSpeed * Time.deltaTime; transform.rotation = Quaternion.Lerp( transform.rotation, Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime ); } else { stateTime = attackStateMaxTime; enemyState = ENEMYSTATE.ATTACK; anim.SetTrigger("attack"); } }
/// <summary> /// 准备怪物转身 /// </summary> /// <param name="nextState">Next state.</param> void _PrepareBodyRotate(ENEMYSTATE nextState) { m_Data.state = ENEMYSTATE.ES_BODY_ROTATE; m_NextState = nextState; }