public void RemoveFromSquad(PikminStates to = PikminStates.Idle) { if (_InSquad) { _InSquad = false; _TargetObject = null; ChangeState(to); PikminStatsManager.RemoveFromSquad(this, _Data._Colour, _CurrentMaturity); PikminStatsManager.ReassignFormation(); } }
public void ChangeState(PikminStates newState) { // There's no saving pikmin from death if (_CurrentState == PikminStates.Dead) { return; } // Shrink collider and grab latch offset to maintain the same position if (newState == PikminStates.Attacking) { _Collider.radius /= 5; _Collider.height /= 5; _LatchOffset = transform.localPosition; if (Physics.Raycast(transform.position, (ClosestPointOnTarget() - transform.position).normalized, out RaycastHit info)) { transform.rotation = Quaternion.LookRotation(info.normal); } } if (_CurrentState == PikminStates.RunningTowards || _CurrentState == PikminStates.Idle && _TargetObject != null) { _TargetObject = null; _TargetObjectCollider = null; } else if (_CurrentState == PikminStates.Attacking) { // Reset latching variables aka regrow collider size and reset the latch offset _Collider.radius *= 5; _Collider.height *= 5; transform.rotation = Quaternion.identity; LatchOnto(null); _MovementVector = Vector3.zero; _AttackingTransform = null; // Check if the object we were attacking was still active or not if (_Attacking == null) { _LatchOffset = Vector3.zero; return; } // As it is still active, and not null, we can call the appropriate function _Attacking.OnAttackEnd(this); _AttackTimer = 0; } _CurrentState = newState; }
void CarryoutIntention() { PikminStates previousState = _CurrentState; // Run intention-specific logic (attack = OnAttackStart for the target object) switch (_Intention) { case PikminIntention.Attack: _AttackingTransform = _TargetObject; _Attacking = _TargetObject.GetComponent <IPikminAttack> (); _Attacking.OnAttackStart(this); LatchOnto(_AttackingTransform); ChangeState(PikminStates.Attacking); break; case PikminIntention.Carry: break; case PikminIntention.PullWeeds: break; case PikminIntention.Idle: ChangeState(PikminStates.Idle); break; default: break; } if (previousState == _CurrentState && _CurrentState != PikminStates.Idle) { ChangeState(PikminStates.Idle); } _Intention = PikminIntention.Idle; }