private void Awake() { chasingState = new ChasingState(this); idleState = new EnemyIdleState(this); returningState = new ReturningState(this); attackingState = new AttackingState(this); visiblePlayers = new List <GameObject>(); returnPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z); eyes = transform.FindChild("Eyes"); health = GetComponent <EnemyHealth>(); attack = GetComponent <EnemyAttack>(); sounds = GetComponent <EnemySoundController>(); animator = GetComponent <EnemyAnimationController>(); navMeshAgent = GetComponent <NavMeshAgent>(); isTargetting = false; if (transform.parent.CompareTag("EnemyMob")) { mobKnowledge = GetComponentInParent <EnemyMobKnowledge>(); } tm = GameObject.FindWithTag("TeamManager").GetComponent <TeamManager>(); }
private void Awake() { m_emergeState = new EmergeState(this); m_chasingState = new ChasingState(this); m_attackState = new AttackState(this); m_jumpToState = new JumpToState(this); m_exhaustState = new ExhaustState(this); }
public StateMachine(Enemy owner, Transform player, EnemyRaw enemyRaw, NavMeshAgent agent, Collider playerCollider, Animator animator, LayerMask layerMask, float chillTime) { this.owner = owner; patrolState = new PatrolState(owner, agent, chillTime); chasingState = new ChasingState(owner, player, agent); attackState = new AttackState(owner, player, agent, playerCollider, animator, layerMask); this.player = player; this.enemyRaw = enemyRaw; }
private void Start() { Debug.Log("Bird"); movementSM = new StateMachine(); flying = new FlyingState(this, movementSM); chasing = new ChasingState(this, movementSM); eating = new EatingState(this, movementSM); resting = new RestingState(this, movementSM); movementSM.Initialize(flying); // Default }
private void MakeFSM() { PatrollingState patrolling = new PatrollingState (this); patrolling.AddTransition(Transition.poiInSight, StateID.Chasing); patrolling.AddTransition(Transition.isDestroyed, StateID.Destroyed); ChasingState chasing = new ChasingState(this); chasing.AddTransition(Transition.poiLost, StateID.Patroling); chasing.AddTransition(Transition.poiInFireingRange, StateID.Attacking); chasing.AddTransition(Transition.isDestroyed, StateID.Destroyed); AttackingState attacking = new AttackingState(this); attacking.AddTransition(Transition.poiLost, StateID.Patroling); attacking.AddTransition(Transition.isDestroyed, StateID.Destroyed); DestroyedState destroyed = new DestroyedState(this); fsm = new FSMSystem(); fsm.AddState(patrolling); fsm.AddState(chasing); fsm.AddState(attacking); fsm.AddState(destroyed); }
public override void UseSpecialPower() { Player player = GameEntitiesManager.Instance.Player; if (Vector2.Distance(Position, player.Position + player.DestinationOrigin) < RANGE_TO_START_CHASING) { _state = ChasingState.Chase; IsRotatable = true; } if (_state == ChasingState.Chase) { Vector2 direction = (player.Position + player.DestinationOrigin) - Position; direction.Normalize(); Body.Velocity = direction * CHASING_MOVE_SPEED; if (Position.X + DestinationOrigin.X < player.Position.X + player.DestinationOrigin.X) { Angle -= ROTATION_SPEED; } else { Angle += ROTATION_SPEED; } } }
//静态创建所有状态 //并初始化当前状态为1 void InitializeAIState() { partolState = new PatrolState(this); chasingState = new ChasingState(this); zombieState = partolState; }