/// <summary> /// Initializes a new instance of the <see cref="CMonster"/> class. /// Default : errance, default radius alert(in G<see cref="CGame"/>), use prefab monster(?). /// </summary> /// <param name='posInit'> /// Position init. The initial position of the monster (no initial rooms ?) /// </param> public CMonster(Vector2 posInit) { m_eMonsterState = EMonsterState.e_MonsterState_errance; m_Game = GameObject.Find("_Game").GetComponent <CGame>(); GameObject prefab = m_Game.prefabMonster; m_GameObject = GameObject.Instantiate(prefab) as GameObject; SetPosition2D(posInit); m_PosDetection = new Vector2(0.0f, 0.0f); m_fRadiusAlerte = m_Game.m_fMonsterRadiusAlerte; }
/// <summary> /// set the state parameters /// </summary> /// <param name='eState'> /// eState : current state /// </param> void SetState(EMonsterState eState) { m_eMonsterState = eState; switch (m_eMonsterState) { case EMonsterState.e_MonsterState_errance: { m_fSpeed = 2; m_bDetectionAudio = true; m_bDetectionVisuelle = true; break; } case EMonsterState.e_MonsterState_affut: { m_bDetectionAudio = true; m_bDetectionVisuelle = true; m_fSpeed = 3; break; } case EMonsterState.e_MonsterState_alerte: { m_bDetectionAudio = true; m_bDetectionVisuelle = true; m_fSpeed = 1; break; } case EMonsterState.e_MonsterState_attaque: { m_bDetectionAudio = true; m_bDetectionVisuelle = false; m_fSpeed = 4; break; } case EMonsterState.e_MonsterState_mange: { m_bDetectionAudio = false; m_bDetectionVisuelle = false; m_fSpeed = 4; break; } } }
// EnemyDamageReceiver calls this method public void Die() { StopAllCoroutines(); _isDie = true; MonsterState = EMonsterState.Die; _navMeshAgent.Stop(); _animator.SetTrigger("IsDie"); gameObject.GetComponentInChildren <CapsuleCollider>().enabled = false; foreach (Collider collider in gameObject.GetComponentsInChildren <SphereCollider>()) { collider.enabled = false; } BroadcastMessage("Drop", _monsterTransform.position, SendMessageOptions.DontRequireReceiver); GameObject player = GameObject.FindWithTag("Player"); player.BroadcastMessage("GainExp", Exp, SendMessageOptions.DontRequireReceiver); Destroy(gameObject, 5.0f); }
IEnumerator CheckMonsterState() { while (!_isDie) { yield return(new WaitForSeconds(0.2f)); // Check distance float distance = Vector3.Distance(_playerTransform.position, _monsterTransform.position); if (distance <= AttackDistance) { MonsterState = EMonsterState.Attack; } else if (distance <= TraceDistance) { MonsterState = EMonsterState.Trace; } else { MonsterState = EMonsterState.Idle; } } }
IEnumerator CheckMonsterState() { while (!_isDie) { yield return new WaitForSeconds(0.2f); // Check distance float distance = Vector3.Distance(_playerTransform.position, _monsterTransform.position); if (distance <= AttackDistance) { MonsterState = EMonsterState.Attack; } else if (distance <= TraceDistance) { MonsterState = EMonsterState.Trace; } else { MonsterState = EMonsterState.Idle; } } }
/// <summary> /// Process /// </summary> /// <param name='fDeltatime'> /// F deltatime. Time between 2 updates. /// </param> public new void Process(float fDeltatime) { base.Process(fDeltatime); ProcessState(fDeltatime); if (m_Game.IsDebug()) { if (Input.GetKeyDown(KeyCode.E)) { // goto next state m_eMonsterState = (m_eMonsterState + 1); if (m_eMonsterState >= EMonsterState.e_MonsterState_nbState) { m_eMonsterState = EMonsterState.e_MonsterState_errance; } SetState(m_eMonsterState); } } if (m_Game.IsDebug()) { ProcessDebug(fDeltatime); } }
// EnemyDamageReceiver calls this method public void Die() { StopAllCoroutines(); _isDie = true; MonsterState = EMonsterState.Die; _navMeshAgent.Stop(); _animator.SetTrigger("IsDie"); gameObject.GetComponentInChildren<CapsuleCollider>().enabled = false; foreach (Collider collider in gameObject.GetComponentsInChildren<SphereCollider>()) { collider.enabled = false; } BroadcastMessage("Drop", _monsterTransform.position, SendMessageOptions.DontRequireReceiver); GameObject player = GameObject.FindWithTag("Player"); player.BroadcastMessage("GainExp", Exp, SendMessageOptions.DontRequireReceiver); Destroy(gameObject, 5.0f); }