// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _playerStateMachine = animator.GetComponent <ICharacterStateMachine>(); _mover = animator.GetComponent <IDirectionMoverComponent>(); _minDistance = _playerStateMachine.DistanceThreshold + _playerStateMachine.ArrivingDistance; }
private void Awake() { // Events initialized in CharacterEvents component // Get gameObject Collider2D references _collider2DArrary = gameObject.GetComponents <Collider2D>(); // Instantiate default character state _characterStateMachine = new CharacterStateGrounded(_characterComponents, _collider2DArrary, _velocity); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _playerStateMachine = animator.GetComponent <ICharacterStateMachine>(); _mover = animator.GetComponent <IDirectionMoverComponent>(); if (_playerStateMachine.TargetObject != null) { if (_playerStateMachine.TargetObject.tag != "Enemy" && _playerStateMachine.TargetObject.tag != "Player") { return; } Vector3 direction = _playerStateMachine.TargetObject.transform.position - _mover.CurrentPosition; _mover.MoveDirection(direction); _mover.MoveDirection(Vector3.zero); } }
//private void Update() //{ // //} #endregion #region FixedUpdate private void FixedUpdate() { // Save last frame gorunded flag bool l_wasGrounded = _characterComponents.CharacterFlags.IsGrounded; // Set grounded flag to false _characterComponents.CharacterFlags.IsGrounded = false; // The player is grounded if a circlecast to the groundcheck position hits anything designated as ground // This can be done using layers instead but Sample Assets will not overwrite your project settings. Collider2D[] colliders = Physics2D. OverlapCircleAll(_characterComponents.GroundCheck.position, CharacterParams.GroundedRadius, _characterComponents.CharacterParams.GroundLayer); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) { _characterComponents.CharacterFlags.IsGrounded = true; _characterComponents.CharacterFlags.HasDoubleJumped = false; _characterComponents.CharacterFlags.WasGliding = false; } } // If previous frame state is different from current frame, then check what state has to be used // This way we avoid to constantly instantiate new state classes, we only do it when it is necessary if (l_wasGrounded != _characterComponents.CharacterFlags.IsGrounded) { // If player was grounded and now it is not... if (l_wasGrounded && !_characterComponents.CharacterFlags.IsGrounded) { _characterStateMachine = new CharacterStateNotGrounded(_characterComponents, _collider2DArrary, _velocity); } // If player was not grounded and now it is... if (!l_wasGrounded && _characterComponents.CharacterFlags.IsGrounded) { _characterStateMachine = new CharacterStateGrounded(_characterComponents, _collider2DArrary, _velocity); } // Trigger grounded event for animator state changes (includes double jump and glide setting) _characterComponents.CharacterEvents.OnGroundedEvent.Invoke(_characterComponents.CharacterFlags.IsGrounded); } }
//OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _playerStateMachine = animator.GetComponent <ICharacterStateMachine>(); _mover = animator.GetComponent <IDirectionMoverComponent>(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _fieldOfView = animator.GetComponent <IFieldOfView>(); _characterStateMachine = animator.GetComponent <ICharacterStateMachine>(); }
private void Awake() { _characterStateMachine = GetComponent <ICharacterStateMachine>(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _playerStateMachine = animator.GetComponent <ICharacterStateMachine>(); animator.speed = _playerStateMachine.AttackSpeed; }
protected override void InitializeOnAwake() { _inputHandlerMousePosition = GetComponent <InputHandlerMousePositionComponent>(); _playerStateMachine = GetComponent <ICharacterStateMachine>(); }