// Update is called once per frame void Update() { if (_beingKilled) { return; } //If we are dead if (_aiHealth.IsDead) { //Change to death state, activates ragdoll and drops weapons stateMachine.ChangeState(AiStateId.Death); _player.GetComponent <PlayerController>().AgentInRange = null; //Destroy the assassination target component and this ai agent component Destroy(GetComponentInChildren <AssassinationTarget>()); Destroy(this); } stateMachine.Update(); _currentState = stateMachine._currentState; if (_player.GetComponent <PlayerHealth>().IsDead) { //Dances, and then stops the AIn from firing and clears the target GetComponent <Animator>().SetBool("PlayerDead", true); GetComponent <NavMeshAgent>().SetDestination(transform.position); _aiWeapon?.SetFiring(false); _aiWeapon?.SetTarget(null); } }
void SetBehaviour() { AdjustSpeed(); if (isEngaging && combatState != null) { stateMachine.ChangeState(combatState); } else { stateMachine.ChangeState(idleState); } }
void Awake() { Behaviour = new AIStateMachine(this); m_state = new AIStateZombie(this); Behaviour.AddState(m_state); Behaviour.ChangeState(m_state); }
public void ChangeAIState(EAIState pAIState) { if (AIState != pAIState) { AIState = pAIState; AIStateMachine.ChangeState(pAIState); } }
protected override void Start() { base.Start(); _stateMachine.Repeat = _repeat; _stateMachine.AlwaysSucceed = _alwaysSucceed; if (_stateMachine.Current == null) { var state = _defaultState as IAIState; if (state == null || !_stateMachine.Contains(state)) { state = _stateMachine.FirstOrDefault(); _defaultState = state as Component; } _stateMachine.ChangeState(state); } }
new private void Start() { stateMachine = new AIStateMachine <AI>(this); stateMachine.ChangeState(idleState.Instance); rigid = gameObject.GetComponent <Rigidbody2D>(); whatIsGround = LayerMask.GetMask("Default"); spawn.transform.position = transform.position; }
// Use this for initialization void Start() { CorePieces = GameObject.FindGameObjectsWithTag("Core"); OutsideWalls = GameObject.FindGameObjectsWithTag("Wall"); EnemyAgent = GetComponent <NavMeshAgent>(); stateMachine = new AIStateMachine <EnemyActionsManagerScript>(this); stateMachine.ChangeState(ChasePlayer.Instance); //SpawnPosition = transform.position; CurrentHealth = MaximumHealth; IsAlive = true; AllCorePiecesGone = false; }
protected override void Begin() { Behaviour = new AIStateMachine(this); AIStateCompanion state = new AIStateCompanion(this); state.target = followTarget; state.minRange = minFollowRange; state.maxRange = maxFollowRange; state.chaseRange = chaseRange; state.attackRange = attackRange; Behaviour.AddState(state); Behaviour.ChangeState(state); }
// Start is called before the first frame update void Start() { //Find the player if (!_player) { _player = GameObject.FindGameObjectWithTag("Player").transform; } stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIDeathState(this)); stateMachine.RegisterState(new AIIdleState(this)); stateMachine.RegisterState(new AICombatState(this)); stateMachine.RegisterState(new AISearchForPlayerState(this)); stateMachine.RegisterState(new AICheckPlayerState(this)); stateMachine.RegisterState(new AIMeleeState(this)); //Registers the patrol state if we have a patrol route if (_route) { stateMachine.RegisterState(new PatrolState(this, _route, _movementSpeedInPatrol, _waitAtEachPointDuration)); } //If we have a starting weapon then instantiate and equip it if (_startingWeapon) { RaycastWeapon weapon = Instantiate(_startingWeapon.Weapon); _aiWeapon = GetComponent <AIWeapons>(); _aiWeapon.EquipWeapon(weapon); } else { Debug.LogError(transform.name + " has no starting weapon"); } stateMachine.ChangeState(_initialState); if (_initialState == AiStateId.CombatState) { Aggrevate(); } }
// Start is called before the first frame update void Start() { //Find the player if (!_player) { _player = GameObject.FindGameObjectWithTag("Player").transform; } stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIDeathState(this)); stateMachine.RegisterState(new BrickAIIdleState(this)); stateMachine.RegisterState(new AIMeleeState(this)); if (_startingWeapon) { RaycastWeapon weapon = Instantiate(_startingWeapon.Weapon); _aiWeapon = GetComponent <AIWeapons>(); _aiWeapon.EquipWeapon(weapon); } stateMachine.ChangeState(_initialState); }
void Start() { //AI DEATH STATE ragdoll = GetComponent <Ragdoll>(); mesh = GetComponentInChildren <SkinnedMeshRenderer>(); healthBar = GetComponentInChildren <UIHealthBar>(); playerTransform = GameObject.FindGameObjectWithTag("Player").transform; navMeshAgent = GetComponent <NavMeshAgent>(); weapons = GetComponent <AIWeapons>(); stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIChasePlayerState()); stateMachine.RegisterState(new AIDeathState()); stateMachine.RegisterState(new AIIdleState()); stateMachine.RegisterState(new AIFindWeaponState()); stateMachine.RegisterState(new AIAttackPlayerState()); stateMachine.ChangeState(initialState); rb = GetComponent <Rigidbody>(); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { AIStateMachine stateMachine = animator.GetComponent <AIStateMachine>(); stateMachine.ChangeState(AIStateType.Idle); }